mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-27 18:37:04 +08:00
Blobbifiyng tenants in mako so that blob granule reads in tenant mode work (#8587)
* Blobbifiyng tenants in mako so that blob granule reads in tenant mode work * removing unecessary comment
This commit is contained in:
parent
8cb2d5e73c
commit
fa80d7bfde
@ -716,6 +716,12 @@ public:
|
|||||||
throwError("Failed to create transaction: ", err);
|
throwError("Failed to create transaction: ", err);
|
||||||
return Transaction(tx_native);
|
return Transaction(tx_native);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TypedFuture<future_var::Bool> blobbifyRange(KeyRef begin, KeyRef end) {
|
||||||
|
if (!tenant)
|
||||||
|
throw std::runtime_error("blobbifyRange from null tenant");
|
||||||
|
return native::fdb_tenant_blobbify_range(tenant.get(), begin.data(), intSize(begin), end.data(), intSize(end));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Database {
|
class Database {
|
||||||
|
@ -283,24 +283,60 @@ int populate(Database db,
|
|||||||
int batch_size = args.tenant_batch_size;
|
int batch_size = args.tenant_batch_size;
|
||||||
int batches = (args.total_tenants + batch_size - 1) / batch_size;
|
int batches = (args.total_tenants + batch_size - 1) / batch_size;
|
||||||
for (int batch = 0; batch < batches; ++batch) {
|
for (int batch = 0; batch < batches; ++batch) {
|
||||||
|
while (1) {
|
||||||
|
for (int i = batch * batch_size; i < args.total_tenants && i < (batch + 1) * batch_size; ++i) {
|
||||||
|
std::string tenant_str = "tenant" + std::to_string(i);
|
||||||
|
Tenant::createTenant(systemTx, toBytesRef(tenant_str));
|
||||||
|
}
|
||||||
|
auto future_commit = systemTx.commit();
|
||||||
|
const auto rc = waitAndHandleError(systemTx, future_commit, "CREATE_TENANT");
|
||||||
|
if (rc == FutureRC::OK) {
|
||||||
|
// Keep going with reset transaction if commit was successful
|
||||||
|
systemTx.reset();
|
||||||
|
break;
|
||||||
|
} else if (rc == FutureRC::RETRY) {
|
||||||
|
// We want to retry this batch. Transaction is already reset
|
||||||
|
} else {
|
||||||
|
// Abort
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Tenant tenants[batch_size];
|
||||||
|
fdb::TypedFuture<fdb::future_var::Bool> blobbifyResults[batch_size];
|
||||||
|
|
||||||
|
// blobbify tenant ranges explicitly
|
||||||
|
// FIXME: skip if database not configured for blob granules?
|
||||||
for (int i = batch * batch_size; i < args.total_tenants && i < (batch + 1) * batch_size; ++i) {
|
for (int i = batch * batch_size; i < args.total_tenants && i < (batch + 1) * batch_size; ++i) {
|
||||||
std::string tenant_name = "tenant" + std::to_string(i);
|
std::string tenant_str = "tenant" + std::to_string(i);
|
||||||
Tenant::createTenant(systemTx, toBytesRef(tenant_name));
|
BytesRef tenant_name = toBytesRef(tenant_str);
|
||||||
|
tenants[i] = db.openTenant(tenant_name);
|
||||||
|
std::string rangeEnd = "\xff";
|
||||||
|
blobbifyResults[i - (batch * batch_size)] =
|
||||||
|
tenants[i].blobbifyRange(BytesRef(), toBytesRef(rangeEnd));
|
||||||
}
|
}
|
||||||
auto future_commit = systemTx.commit();
|
|
||||||
const auto rc = waitAndHandleError(systemTx, future_commit, "CREATE_TENANT");
|
for (int i = batch * batch_size; i < args.total_tenants && i < (batch + 1) * batch_size; ++i) {
|
||||||
if (rc == FutureRC::OK) {
|
while (true) {
|
||||||
// Keep going with reset transaction if commit was successful
|
// not technically an operation that's part of systemTx, but it works
|
||||||
systemTx.reset();
|
const auto rc =
|
||||||
} else if (rc == FutureRC::RETRY) {
|
waitAndHandleError(systemTx, blobbifyResults[i - (batch * batch_size)], "BLOBBIFY_TENANT");
|
||||||
// We want to retry this batch, so decrement the number
|
if (rc == FutureRC::OK) {
|
||||||
// and go back through the loop to get the same value
|
if (!blobbifyResults[i - (batch * batch_size)].get()) {
|
||||||
// Transaction is already reset
|
fmt::print("Blobbifying tenant {0} failed!\n", i);
|
||||||
--batch;
|
return -1;
|
||||||
} else {
|
}
|
||||||
// Abort
|
break;
|
||||||
return -1;
|
} else if (rc == FutureRC::RETRY) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
// Abort
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
systemTx.reset();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::string last_tenant_name = "tenant" + std::to_string(args.total_tenants - 1);
|
std::string last_tenant_name = "tenant" + std::to_string(args.total_tenants - 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user