Mongo is a one-member replica set
Owner decision 2026-10-07: production's mongod becomes a one-member replica set (rs0), so that a backup can read every collection at one instant (a snapshot read session), which a standalone mongod can't. The unit runs mongod with --replSet rs0 and a 990 MB oplog; setup.sh converts it once, idempotently (PrivaPub stopped, mongod restarted, rs.initiate, the primary awaited, PrivaPub started); every connection string says directConnection=true, which works against the standalone too, so this code can deploy before the conversion. The CI's throwaway mongod and the pasture's are replica sets as well, so the snapshot path is what the tests exercise; MongoTopology tells which a mongod is, and TopologyTests holds the test mongod to it. The suite passes on it (906). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LsXgEaXee4GCU1hwYgPJXw
This commit is contained in:
1 parent
830385ea2b
commit
37b12c5fee
10 files changed
+90
-11
No files matched your search
@@ -0,0 +1,23 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace PrivaPub.Infrastructure.Data
|
||||
{
|
||||
// Whether the mongod is a replica set member (production's is a one-member set, rs0): only then can a read session
|
||||
// hold one point in time across collections (a snapshot), which a backup needs to be consistent.
|
||||
public static class MongoTopology
|
||||
{
|
||||
public static async Task<bool> IsReplicaSet(IMongoDatabase database, CancellationToken token)
|
||||
{
|
||||
try
|
||||
{
|
||||
var hello = await database.Client.GetDatabase("admin").RunCommandAsync<BsonDocument>(new BsonDocument("hello", 1), cancellationToken: token);
|
||||
return hello.Contains("setName");
|
||||
}
|
||||
catch (MongoCommandException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@
|
||||
"MongoSettings": {
|
||||
"Database": "PrivaPub",
|
||||
"LogsDatabase": "logs",
|
||||
"ConnectionString": "mongodb://127.0.0.1:27022"
|
||||
"ConnectionString": "mongodb://127.0.0.1:27022/?directConnection=true"
|
||||
},
|
||||
"AppConfiguration": {
|
||||
"Version": "0.0.0",
|
||||
@@ -74,7 +74,7 @@
|
||||
{
|
||||
"Name": "MongoDBCapped",
|
||||
"Args": {
|
||||
"databaseUrl": "mongodb://127.0.0.1:27022/logs",
|
||||
"databaseUrl": "mongodb://127.0.0.1:27022/logs?directConnection=true",
|
||||
"collectionName": "PrivaPub",
|
||||
"cappedMaxSizeMb": "1024",
|
||||
"cappedMaxDocuments": "10000"
|
||||
|
||||
Reference in new issue
Block a user