move data to value and parse it

This commit is contained in:
Dan Lambright 2023-12-18 09:10:06 -05:00
parent a20f9d3475
commit 5ebe8b0915
4 changed files with 54 additions and 36 deletions

View File

@ -1341,26 +1341,22 @@ Key uidPrefixKey(KeyRef keyPrefix, UID logUid) {
return bw.toValue();
}
std::tuple<uint64_t, uint64_t, uint64_t> decodeConstructKeys(KeyRef keyValue) {
uint64_t start, stop, length;
BinaryReader rd(keyValue.removePrefix(constructDataKey), Unversioned());
rd >> start;
start = stop = length = 0;
rd >> stop;
rd >> length;
return std::make_tuple(start, stop, length);
std::tuple<Standalone<StringRef>, uint64_t, uint64_t> decodeConstructKeys(ValueRef value) {
StringRef keyStart;
uint64_t keySize, keyCount;
BinaryReader rd(value, Unversioned());
rd >> keyStart;
rd >> keySize;
rd >> keyCount;
return std::make_tuple(keyStart, keySize, keyCount);
}
Value encodeConstructKeys(uint64_t keyNum) {
Value encodeConstructValue(StringRef keyStart, uint64_t keySize, uint64_t keyCount, uint64_t seed) {
BinaryWriter wr(Unversioned());
wr.serializeBytes("\xbf/constructData/"_sr);
wr << bigEndian64(keyNum);
return wr.toValue();
}
Value encodeConstructValue(uint64_t seed) {
BinaryWriter wr(Unversioned());
wr << bigEndian64(seed);
wr << keyStart;
wr << keySize;
wr << keyCount;
// wr << seed;
return wr.toValue();
}

View File

@ -545,9 +545,8 @@ Key logRangesEncodeValue(KeyRef keyEnd, KeyRef destPath);
// the given uid encoded at the end
Key uidPrefixKey(KeyRef keyPrefix, UID logUid);
extern std::tuple<uint64_t, uint64_t, uint64_t> decodeConstructKeys(KeyRef keyValue);
extern Value encodeConstructKeys(uint64_t keyNum);
extern Value encodeConstructValue(uint64_t seed);
extern std::tuple<Standalone<StringRef>, uint64_t, uint64_t> decodeConstructKeys(ValueRef value);
extern Value encodeConstructValue(StringRef keyStart, uint64_t keySize, uint64_t keyCount, uint64_t seed);
/// Apply mutations constant variables

View File

@ -585,14 +585,19 @@ private:
}
if (m.param1.startsWith(constructDataKey)) {
std::tuple<uint64_t, uint64_t, uint64_t> t = decodeConstructKeys(m.param1);
uint64_t first_element, second_element, third_element;
std::tie(first_element, second_element, third_element) = t;
TraceEvent("DANHERE").detail("V", m.param2);
// std::string safeLocality = BinaryReader::fromStringRef<std::string>(m.param2, Unversioned());
// TraceEvent("DANHERE2").detail("V",safeLocality);
std::tuple<Standalone<StringRef>, uint64_t, uint64_t> t = decodeConstructKeys(m.param2);
uint64_t second_element = std::get<1>(t), third_element = std::get<2>(t);
Standalone<StringRef> first_element = std::get<0>(t);
// m.param2 = encodelConstructValue("\xcf\xdf"_sr, second_element, third_element, 0);
TraceEvent("DANHERE")
.detail("F1", first_element)
.detail("F2", second_element)
.detail("F3", third_element)
.detail("S", m.param1.size());
.detail("S", m.param2);
}
}

View File

@ -1013,7 +1013,7 @@ public:
pendingAddRanges; // Pending requests to add ranges to physical shards
std::map<Version, std::vector<KeyRange>>
pendingRemoveRanges; // Pending requests to remove ranges from physical shards
std::deque<MutationRef> constructedData;
std::deque<std::pair<Standalone<StringRef>, Standalone<StringRef>>> constructedData;
bool shardAware; // True if the storage server is aware of the physical shards.
@ -10857,19 +10857,34 @@ private:
}
}
} else if (m.param1.substr(1).startsWith(constructDataKey)) {
MutationRef constructedMutation;
constructedMutation.type = MutationRef::SetValue;
TraceEvent("DANCONSTRUCTSS2").detail("S", constructedMutation.param1.size());
std::tuple<uint64_t, uint64_t, uint64_t> t = decodeConstructKeys(m.param1.substr(1));
uint64_t first_element, second_element, third_element;
std::tie(first_element, second_element, third_element) = t;
constructedMutation.param1 = "\xbf/constructData/"_sr; // encodeConstructKeys(first_element);
constructedMutation.param2 = encodeConstructValue(23);
data->constructedData.push_back(constructedMutation);
std::tuple<Standalone<StringRef>, uint64_t, uint64_t> t = decodeConstructKeys(m.param2);
std::pair<Standalone<StringRef>, Standalone<StringRef>> m;
uint64_t second_element, third_element;
std::tie(m.first, second_element, third_element) = t;
// constructedMutation.param1 = first_element;
m.second = "23"_sr; // ;//encodeConstructValue(23);
data->constructedData.push_back(m);
TraceEvent("DANCONSTRUCTSS")
.detail("F1", first_element)
.detail("F1", data->constructedData.front().first)
.detail("F2", second_element)
.detail("F3", third_element);
// int seed=0; // from constructData
// for (int key=0; key<numKeys; key++) {
// MutationRef constructedMutation;
// constructedMutation.type = MutationRef::SetValue;
// constructedMutation.param1 = "\xbf/constructData/"_sr;
// // append 'key' to param1
// for (int v=0; v < sizeValue; v++) {
// // append random char to param2
// const char *param2_value = "23";
// constructedMutation.param2 = param2_value;
// }
// data->constructedData.push_back(constructedMutation);
// TraceEvent("DANCONSTRUCTSS")
// .detail("F1", firstKey)
// .detail("F2", sizeValue)
// .detail("F3", numKeys);
// }
} else {
ASSERT(false); // Unknown private mutation
}
@ -11350,7 +11365,10 @@ ACTOR Future<Void> update(StorageServer* data, bool* pReceivedUpdate) {
} else if (ver != invalidVersion) { // This change belongs to a version < minVersion
if (data->constructedData.size()) {
MutationRef constructedMutation = data->constructedData.front();
MutationRef constructedMutation;
constructedMutation.type = MutationRef::SetValue;
constructedMutation.param1 = data->constructedData.front().first;
constructedMutation.param2 = data->constructedData.front().second;
TraceEvent("DANPULL").detail("T", constructedMutation.param1);
updater.applyMutation(data, constructedMutation, encryptedMutation, ver, false);
data->constructedData.pop_front();