handle prefix convert to negative id

This commit is contained in:
Xiaoxi Wang 2023-02-03 12:26:25 -08:00
parent 0e242226bc
commit b0902a515a
2 changed files with 18 additions and 12 deletions

View File

@ -1105,11 +1105,12 @@ inline int64_t lowerBoundTenantId(const StringRef& prefix, const std::map<int64_
// fall to generate a prefix
id = TenantIdCodec::lowerBound(prefix);
}
auto it = tenantMap.lower_bound(id.get());
if (it != tenantMap.end()) {
return it->first;
if (id.present() && id.get() >= 0) {
auto it = tenantMap.lower_bound(id.get());
if (it != tenantMap.end()) {
return it->first;
}
}
return TenantInfo::INVALID_TENANT;
}
@ -1129,6 +1130,9 @@ TEST_CASE("/CommitProxy/SplitRange/LowerBoundTenantId") {
tid = lowerBoundTenantId("\xff\x01\x02\x03\x04\x05\x06\x07\x08"_sr, tenantMap);
ASSERT_EQ(tid, TenantInfo::INVALID_TENANT);
tid = lowerBoundTenantId("\x99\x01\x02\x03\x04\x05\x06\x07\x08"_sr, tenantMap);
ASSERT_EQ(tid, TenantInfo::INVALID_TENANT);
int64_t targetId = deterministicRandom()->randomInt64(0, mapSize) * 2;
Key prefix = TenantAPI::idToPrefix(targetId);
tid = lowerBoundTenantId(prefix, tenantMap);
@ -1267,7 +1271,6 @@ void replaceRawClearRanges(Arena& arena,
mutations.resize(arena, totalSize);
// place from back
int curr = totalSize - 1;
bool doValidation = g_network->isSimulated();
for (; i >= 0; --i) {
if (splitMutations.empty()) {
ASSERT_EQ(curr, i);
@ -1322,9 +1325,9 @@ Error validateAndProcessTenantAccess(Arena& arena,
newMutationSize += newClears.size() - 1;
}
if (debugId.present()) {
if (debugId.present() || true) {
TraceEvent(SevDebug, "SplitTenantClearRange", pProxyCommitData->dbgid)
.detail("TxnId", debugId.get())
// .detail("TxnId", debugId.get())
.detail("Idx", i)
.detail("NewMutationSize", newMutationSize)
.detail("OldMutationSize", mutations.size())
@ -1335,17 +1338,18 @@ Error validateAndProcessTenantAccess(Arena& arena,
writeNormalKey = true;
}
if (debugId.present()) {
if (debugId.present() || true) {
TraceEvent(SevDebug, "ValidateAndProcessTenantAccess", pProxyCommitData->dbgid)
.detail("Context", context)
.detail("TxnId", debugId.get())
// .detail("TxnId", debugId.get())
.detail("Version", pProxyCommitData->version.get())
.detail("ChangeTenant", changeTenant)
.detail("WriteNormalKey", writeNormalKey)
.detail("TenantId", tenantId)
.detail("ValidAccess", validAccess)
.detail("MutationType", getTypeString(mutation.type))
.detail("Mutation", mutation.param1);
.detail("Mutation1", mutation.param1)
.detail("Mutation2", mutation.param2);
}
if (!validAccess) {

View File

@ -343,6 +343,8 @@ struct RawTenantAccessWorkload : TestWorkload {
// 2. write a nonexistent tenant is illegal. (invalidTenantWriteOp == true)
bool legalTxnOnly = deterministicRandom()->coinflip(); // whether allow generating illegal transaction
bool validTenantWriteOnly = deterministicRandom()->coinflip(); // whether only write to existing tenants
bool noTenantChange = deterministicRandom()->coinflip();
bool normalKeyWriteOp = false;
bool tenantMapChangeOp = false;
@ -351,12 +353,12 @@ struct RawTenantAccessWorkload : TestWorkload {
lastCreatedTenants.clear();
for (int i = 0; i < 10; ++i) {
int op = deterministicRandom()->randomInt(0, 4);
if (op == 0 && hasNonexistentTenant() && !(legalTxnOnly && normalKeyWriteOp)) {
if (op == 0 && hasNonexistentTenant() && !(legalTxnOnly && normalKeyWriteOp) && !noTenantChange) {
// whether to create a new Tenant
txnOps.emplace_back(CREATE_TENANT, chooseNonexistentTenant());
lastCreatedTenants.emplace(txnOps.back().second);
tenantMapChangeOp = true;
} else if (op == 1 && hasExistingTenant() && !(legalTxnOnly && normalKeyWriteOp)) {
} else if (op == 1 && hasExistingTenant() && !(legalTxnOnly && normalKeyWriteOp) && !noTenantChange) {
// whether to delete an existing tenant
txnOps.emplace_back(DELETE_TENANT, chooseExistingTenant());
lastDeletedTenants.emplace(txnOps.back().second);