diff --git a/fdbserver/BlobWorker.actor.cpp b/fdbserver/BlobWorker.actor.cpp index 26ebca1c79..edc45f9a6c 100644 --- a/fdbserver/BlobWorker.actor.cpp +++ b/fdbserver/BlobWorker.actor.cpp @@ -208,9 +208,13 @@ struct BlobWorkerData : NonCopyable, ReferenceCounted { int changeFeedStreamReplyBufferSize = SERVER_KNOBS->BG_DELTA_FILE_TARGET_BYTES / 2; + bool isEncryptionEnabled = false; + BlobWorkerData(UID id, Reference const> dbInf, Database db) : id(id), db(db), stats(id, SERVER_KNOBS->WORKER_LOGGING_INTERVAL), tenantData(BGTenantMap(dbInf)), dbInfo(dbInf), - initialSnapshotLock(SERVER_KNOBS->BLOB_WORKER_INITIAL_SNAPSHOT_PARALLELISM) {} + initialSnapshotLock(SERVER_KNOBS->BLOB_WORKER_INITIAL_SNAPSHOT_PARALLELISM), + isEncryptionEnabled( + isEncryptionOpSupported(EncryptOperationType::BLOB_GRANULE_ENCRYPTION, db->clientInfo->get())) {} bool managerEpochOk(int64_t epoch) { if (epoch < currentManagerEpoch) { @@ -626,7 +630,7 @@ ACTOR Future writeDeltaFile(Reference bwData, state Optional cipherKeysMeta; state Arena arena; - if (isEncryptionOpSupported(EncryptOperationType::BLOB_GRANULE_ENCRYPTION, bwData->dbInfo->get().client)) { + if (bwData->isEncryptionEnabled) { BlobGranuleCipherKeysCtx ciphKeysCtx = wait(getLatestGranuleCipherKeys(bwData, keyRange, &arena)); cipherKeysCtx = std::move(ciphKeysCtx); cipherKeysMeta = BlobGranuleCipherKeysCtx::toCipherKeysMeta(cipherKeysCtx.get()); @@ -826,7 +830,7 @@ ACTOR Future writeSnapshot(Reference bwData, state Optional cipherKeysMeta; state Arena arena; - if (isEncryptionOpSupported(EncryptOperationType::BLOB_GRANULE_ENCRYPTION, bwData->dbInfo->get().client)) { + if (bwData->isEncryptionEnabled) { BlobGranuleCipherKeysCtx ciphKeysCtx = wait(getLatestGranuleCipherKeys(bwData, keyRange, &arena)); cipherKeysCtx = std::move(ciphKeysCtx); cipherKeysMeta = BlobGranuleCipherKeysCtx::toCipherKeysMeta(cipherKeysCtx.get()); @@ -1053,8 +1057,7 @@ ACTOR Future compactFromBlob(Reference bwData, state Optional snapCipherKeysCtx; if (snapshotF.cipherKeysMeta.present()) { - ASSERT( - isEncryptionOpSupported(EncryptOperationType::BLOB_GRANULE_ENCRYPTION, bwData->dbInfo->get().client)); + ASSERT(bwData->isEncryptionEnabled); BlobGranuleCipherKeysCtx keysCtx = wait(getGranuleCipherKeysFromKeysMeta(bwData, snapshotF.cipherKeysMeta.get(), &filenameArena)); @@ -3370,8 +3373,7 @@ ACTOR Future doBlobGranuleFileRequest(Reference bwData, Bl } if (encrypted) { - ASSERT(isEncryptionOpSupported(EncryptOperationType::BLOB_GRANULE_ENCRYPTION, - bwData->dbInfo->get().client)); + ASSERT(bwData->isEncryptionEnabled); ASSERT(!chunk.snapshotFile.get().cipherKeysCtx.present()); snapCipherKeysCtx = getGranuleCipherKeysFromKeysMetaRef( @@ -3389,8 +3391,7 @@ ACTOR Future doBlobGranuleFileRequest(Reference bwData, Bl } if (encrypted) { - ASSERT(isEncryptionOpSupported(EncryptOperationType::BLOB_GRANULE_ENCRYPTION, - bwData->dbInfo->get().client)); + ASSERT(bwData->isEncryptionEnabled); ASSERT(!chunk.deltaFiles[deltaIdx].cipherKeysCtx.present()); deltaCipherKeysCtxs.emplace( diff --git a/fdbserver/CommitProxyServer.actor.cpp b/fdbserver/CommitProxyServer.actor.cpp index dbc49377ff..5d445f53a2 100644 --- a/fdbserver/CommitProxyServer.actor.cpp +++ b/fdbserver/CommitProxyServer.actor.cpp @@ -917,7 +917,7 @@ ACTOR Future getResolution(CommitBatchContext* self) { // Fetch cipher keys if needed. state Future>> getCipherKeys; - if (isEncryptionOpSupported(EncryptOperationType::TLOG_ENCRYPTION, pProxyCommitData->db->get().client)) { + if (pProxyCommitData->isEncryptionEnabled) { static std::unordered_map defaultDomains = { { SYSTEM_KEYSPACE_ENCRYPT_DOMAIN_ID, FDB_DEFAULT_ENCRYPT_DOMAIN_NAME }, { ENCRYPT_HEADER_DOMAIN_ID, FDB_DEFAULT_ENCRYPT_DOMAIN_NAME } @@ -960,7 +960,7 @@ ACTOR Future getResolution(CommitBatchContext* self) { g_traceBatch.addEvent( "CommitDebug", self->debugID.get().first(), "CommitProxyServer.commitBatch.AfterResolution"); } - if (isEncryptionOpSupported(EncryptOperationType::TLOG_ENCRYPTION, pProxyCommitData->db->get().client)) { + if (pProxyCommitData->isEncryptionEnabled) { std::unordered_map> cipherKeys = wait(getCipherKeys); self->cipherKeys = cipherKeys; } @@ -1098,20 +1098,17 @@ ACTOR Future applyMetadataToCommittedTransactions(CommitBatchContext* self trs[t].reply.sendError(result.getError()); } else { self->commitCount++; - applyMetadataMutations( - trs[t].spanContext, - *pProxyCommitData, - self->arena, - pProxyCommitData->logSystem, - trs[t].transaction.mutations, - SERVER_KNOBS->PROXY_USE_RESOLVER_PRIVATE_MUTATIONS ? nullptr : &self->toCommit, - isEncryptionOpSupported(EncryptOperationType::TLOG_ENCRYPTION, pProxyCommitData->db->get().client) - ? &self->cipherKeys - : nullptr, - self->forceRecovery, - self->commitVersion, - self->commitVersion + 1, - /* initialCommit= */ false); + applyMetadataMutations(trs[t].spanContext, + *pProxyCommitData, + self->arena, + pProxyCommitData->logSystem, + trs[t].transaction.mutations, + SERVER_KNOBS->PROXY_USE_RESOLVER_PRIVATE_MUTATIONS ? nullptr : &self->toCommit, + pProxyCommitData->isEncryptionEnabled ? &self->cipherKeys : nullptr, + self->forceRecovery, + self->commitVersion, + self->commitVersion + 1, + /* initialCommit= */ false); } } if (self->firstStateMutations) { @@ -1162,8 +1159,7 @@ ACTOR Future applyMetadataToCommittedTransactions(CommitBatchContext* self void writeMutation(CommitBatchContext* self, int64_t tenantId, const MutationRef& mutation) { static_assert(TenantInfo::INVALID_TENANT == ENCRYPT_INVALID_DOMAIN_ID); - if (!isEncryptionOpSupported(EncryptOperationType::TLOG_ENCRYPTION, self->pProxyCommitData->db->get().client) || - tenantId == TenantInfo::INVALID_TENANT) { + if (!self->pProxyCommitData->isEncryptionEnabled || tenantId == TenantInfo::INVALID_TENANT) { // TODO(yiwu): In raw access mode, use tenant prefix to figure out tenant id for user data bool isRawAccess = tenantId == TenantInfo::INVALID_TENANT && !isSystemKey(mutation.param1) && !(mutation.type == MutationRef::ClearRange && isSystemKey(mutation.param2)) && diff --git a/fdbserver/include/fdbserver/ProxyCommitData.actor.h b/fdbserver/include/fdbserver/ProxyCommitData.actor.h index b6a75f7ea7..c086263c91 100644 --- a/fdbserver/include/fdbserver/ProxyCommitData.actor.h +++ b/fdbserver/include/fdbserver/ProxyCommitData.actor.h @@ -19,6 +19,7 @@ */ #pragma once +#include "fdbserver/EncryptionOpsUtils.h" #if defined(NO_INTELLISENSE) && !defined(FDBSERVER_PROXYCOMMITDATA_ACTOR_G_H) #define FDBSERVER_PROXYCOMMITDATA_ACTOR_G_H #include "fdbserver/ProxyCommitData.actor.g.h" @@ -231,6 +232,8 @@ struct ProxyCommitData { double lastResolverReset; int localTLogCount = -1; + bool isEncryptionEnabled = false; + // The tag related to a storage server rarely change, so we keep a vector of tags for each key range to be slightly // more CPU efficient. When a tag related to a storage server does change, we empty out all of these vectors to // signify they must be repopulated. We do not repopulate them immediately to avoid a slow task. @@ -299,7 +302,8 @@ struct ProxyCommitData { cx(openDBOnServer(db, TaskPriority::DefaultEndpoint, LockAware::True)), db(db), singleKeyMutationEvent(LiteralStringRef("SingleKeyMutation")), lastTxsPop(0), popRemoteTxs(false), lastStartCommit(0), lastCommitLatency(SERVER_KNOBS->REQUIRED_MIN_RECOVERY_DURATION), lastCommitTime(0), - lastMasterReset(now()), lastResolverReset(now()) { + lastMasterReset(now()), lastResolverReset(now()), + isEncryptionEnabled(isEncryptionOpSupported(EncryptOperationType::TLOG_ENCRYPTION, db->get().client)) { commitComputePerOperation.resize(SERVER_KNOBS->PROXY_COMPUTE_BUCKETS, 0.0); } };