summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp')
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp
index 7d4e635daec..1b30456d4de 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_chunk_operations.cpp
@@ -45,6 +45,7 @@
#include "mongo/db/repl/repl_client_info.h"
#include "mongo/db/s/sharding_logging.h"
#include "mongo/db/server_options.h"
+#include "mongo/db/snapshot_window_options_gen.h"
#include "mongo/logv2/log.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
@@ -777,19 +778,28 @@ StatusWith<BSONObj> ShardingCatalogManager::commitChunkMigration(
// Copy the complete history.
auto newHistory = origChunk.getValue().getHistory();
- const int kHistorySecs = 10;
-
invariant(validAfter);
- // Update the history of the migrated chunk.
- // Drop the history that is too old (10 seconds of history for now).
- // TODO SERVER-33831 to update the old history removal policy.
+ // Drop old history. Keep at least 1 entry so ChunkInfo::getShardIdAt finds valid history for
+ // any query younger than the history window.
if (!MONGO_unlikely(skipExpiringOldChunkHistory.shouldFail())) {
- while (!newHistory.empty() &&
- newHistory.back().getValidAfter().getSecs() + kHistorySecs <
+ const int kHistorySecs = 10;
+ auto windowInSeconds = std::max(minSnapshotHistoryWindowInSeconds.load(), kHistorySecs);
+ int entriesDeleted = 0;
+ while (newHistory.size() > 1 &&
+ newHistory.back().getValidAfter().getSecs() + windowInSeconds <
validAfter.get().getSecs()) {
newHistory.pop_back();
+ ++entriesDeleted;
+ }
+
+ logv2::DynamicAttributes attrs;
+ attrs.add("entriesDeleted", entriesDeleted);
+ if (!newHistory.empty()) {
+ attrs.add("oldestEntryValidAfter", newHistory.back().getValidAfter());
}
+
+ LOGV2_DEBUG(4778500, 1, "Deleted old chunk history entries", attrs);
}
if (!newHistory.empty() && newHistory.front().getValidAfter() >= validAfter.get()) {