From 0ac2a24b8f56d376f231908cea710607876b69e1 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 8 Mar 2017 00:54:33 +0100 Subject: [PATCH 1/3] Adding replSetGetConfig structs --- src/go/mongolib/proto/replconfig.go | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/go/mongolib/proto/replconfig.go diff --git a/src/go/mongolib/proto/replconfig.go b/src/go/mongolib/proto/replconfig.go new file mode 100644 index 00000000..d0e77be1 --- /dev/null +++ b/src/go/mongolib/proto/replconfig.go @@ -0,0 +1,49 @@ +package proto + +import ( + "gopkg.in/mgo.v2/bson" +) + +type ReplConfigTags map[string]string +type GetLastErrorModes map[string]*ReplConfigTags + +// https://docs.mongodb.com/v3.2/reference/command/getLastError/#dbcmd.getLastError +type GetLastErrorDefaults struct { + Journal bool `bson:"j,omitempty"` // If true, wait for the next journal commit before returning, rather than waiting for a full disk flush. + WriteConcern int64 `bson:"w,omitempty"` // When running with replication, this is the number of servers to replicate to before returning. + WTimeout int64 `bson:"wtimeout,omitempty"` // Optional. Milliseconds. Specify a value in milliseconds to control how long to wait for write propagation to complete. +} + +// https://docs.mongodb.com/v3.2/reference/replica-configuration/#rsconf.members +type ReplConfigMember struct { + ID int64 `bson:"_id,omitempty"` // An integer identifier of every member in the replica set. + Host string `bson:"host,omitempty"` // The hostname and, if specified, the port number, of the set member. + ArbiterOnly bool `bson:"arbiterOnly,omitempty"` // A boolean that identifies an arbiter. A value of true indicates that the member is an arbiter. + BuildIndexes bool `bson:"buildIndexes,omitempty"` // A boolean that indicates whether the mongod builds indexes on this member. + Hidden bool `bson:"hidden,omitempty"` // When this value is true, the replica set hides this instance and does not include the member in the output of db.isMaster() or isMaster. + Priority int64 `bson:"priority,omitempty"` // A number that indicates the relative eligibility of a member to become a primary. + Tags *ReplConfigTags `bson:"tags,omitempty"` // A tag set document containing mappings of arbitrary keys and values. + SlaveDelay int64 `bson:"slaveDelay,omitempty"` // The number of seconds “behind” the primary that this replica set member should “lag”. + Votes int64 `bson:"votes,omitempty"` // The number of votes a server will cast in a replica set election. +} + +// https://docs.mongodb.com/v3.2/reference/replica-configuration/#rsconf.settings +type ReplicaSetConfigSettings struct { + ChainingAllowed bool `bson:"chainingAllowed,omitempty"` // When chainingAllowed is true, the replica set allows secondary members to replicate from other secondary members. + HeartbeatTimeoutSecs int64 `bson:"heartbeatTimeoutSecs,omitempty"` // Number of seconds that the replica set members wait for a successful heartbeat from each other. + HeartbeatIntervalMillis int64 `bson:"heartbeatIntervalMillis,omitempty"` // The frequency in milliseconds of the heartbeats. + ElectionTimeoutMillis int64 `bson:"electionTimeoutMillis,omitempty"` // The time limit in milliseconds for detecting when a replica set’s primary is unreachable. + GetLastErrorDefaults *GetLastErrorDefaults `bson:"getLastErrorDefaults,omitempty"` // A document that specifies the write concern for the replica set. + GetLastErrorModes *GetLastErrorModes `bson:"getLastErrorModes,omitempty"` // A document used to define an extended write concern through the use of members[n].tags. + ReplicaSetId *bson.ObjectId `bson:"replicaSetId,omitempty"` // Replset Id (ObjectId) +} + +type ReplicaSetConfig struct { + Config struct { + ID string `bson:"_id,omitempty"` // The name of the replica set. Once set, you cannot change the name of a replica set. + Version int64 `bson:"version,omitempty"` // An incrementing number used to distinguish revisions of the replica set configuration object from previous iterations. + Members []*ReplConfigMember `bson:"members,omitempty"` // An array of member configuration documents, one for each member of the replica set. + Settings *ReplicaSetConfigSettings `bson:"settings,omitempty"` // A document that contains configuration options that apply to the whole replica set. + } `bson:"config,omitempty"` // https://docs.mongodb.com/v3.2/reference/replica-configuration/#replica-set-configuration-fields + Ok int64 `bson:"ok,omitempty"` +} From d8498a2591e5960e02e438eebd27cf2c19c489c0 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 8 Mar 2017 00:58:28 +0100 Subject: [PATCH 2/3] Rename sub-structs more consistently --- src/go/mongolib/proto/replconfig.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/go/mongolib/proto/replconfig.go b/src/go/mongolib/proto/replconfig.go index d0e77be1..92af4d6e 100644 --- a/src/go/mongolib/proto/replconfig.go +++ b/src/go/mongolib/proto/replconfig.go @@ -4,8 +4,8 @@ import ( "gopkg.in/mgo.v2/bson" ) -type ReplConfigTags map[string]string -type GetLastErrorModes map[string]*ReplConfigTags +type ReplicaSetConfigTags map[string]string +type GetLastErrorModes map[string]*ReplicaSetConfigTags // https://docs.mongodb.com/v3.2/reference/command/getLastError/#dbcmd.getLastError type GetLastErrorDefaults struct { @@ -15,16 +15,16 @@ type GetLastErrorDefaults struct { } // https://docs.mongodb.com/v3.2/reference/replica-configuration/#rsconf.members -type ReplConfigMember struct { - ID int64 `bson:"_id,omitempty"` // An integer identifier of every member in the replica set. - Host string `bson:"host,omitempty"` // The hostname and, if specified, the port number, of the set member. - ArbiterOnly bool `bson:"arbiterOnly,omitempty"` // A boolean that identifies an arbiter. A value of true indicates that the member is an arbiter. - BuildIndexes bool `bson:"buildIndexes,omitempty"` // A boolean that indicates whether the mongod builds indexes on this member. - Hidden bool `bson:"hidden,omitempty"` // When this value is true, the replica set hides this instance and does not include the member in the output of db.isMaster() or isMaster. - Priority int64 `bson:"priority,omitempty"` // A number that indicates the relative eligibility of a member to become a primary. - Tags *ReplConfigTags `bson:"tags,omitempty"` // A tag set document containing mappings of arbitrary keys and values. - SlaveDelay int64 `bson:"slaveDelay,omitempty"` // The number of seconds “behind” the primary that this replica set member should “lag”. - Votes int64 `bson:"votes,omitempty"` // The number of votes a server will cast in a replica set election. +type ReplicaSetConfigMember struct { + ID int64 `bson:"_id,omitempty"` // An integer identifier of every member in the replica set. + Host string `bson:"host,omitempty"` // The hostname and, if specified, the port number, of the set member. + ArbiterOnly bool `bson:"arbiterOnly,omitempty"` // A boolean that identifies an arbiter. A value of true indicates that the member is an arbiter. + BuildIndexes bool `bson:"buildIndexes,omitempty"` // A boolean that indicates whether the mongod builds indexes on this member. + Hidden bool `bson:"hidden,omitempty"` // When this value is true, the replica set hides this instance and does not include the member in the output of db.isMaster() or isMaster. + Priority int64 `bson:"priority,omitempty"` // A number that indicates the relative eligibility of a member to become a primary. + Tags *ReplicaSetConfigTags `bson:"tags,omitempty"` // A tag set document containing mappings of arbitrary keys and values. + SlaveDelay int64 `bson:"slaveDelay,omitempty"` // The number of seconds “behind” the primary that this replica set member should “lag”. + Votes int64 `bson:"votes,omitempty"` // The number of votes a server will cast in a replica set election. } // https://docs.mongodb.com/v3.2/reference/replica-configuration/#rsconf.settings @@ -42,7 +42,7 @@ type ReplicaSetConfig struct { Config struct { ID string `bson:"_id,omitempty"` // The name of the replica set. Once set, you cannot change the name of a replica set. Version int64 `bson:"version,omitempty"` // An incrementing number used to distinguish revisions of the replica set configuration object from previous iterations. - Members []*ReplConfigMember `bson:"members,omitempty"` // An array of member configuration documents, one for each member of the replica set. + Members []*ReplicaSetConfigMember `bson:"members,omitempty"` // An array of member configuration documents, one for each member of the replica set. Settings *ReplicaSetConfigSettings `bson:"settings,omitempty"` // A document that contains configuration options that apply to the whole replica set. } `bson:"config,omitempty"` // https://docs.mongodb.com/v3.2/reference/replica-configuration/#replica-set-configuration-fields Ok int64 `bson:"ok,omitempty"` From ae19d885fe4e6f50af0c5d24a9b77a4a3ac1151d Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 8 Mar 2017 01:14:43 +0100 Subject: [PATCH 3/3] add protocolVersion --- src/go/mongolib/proto/replconfig.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/go/mongolib/proto/replconfig.go b/src/go/mongolib/proto/replconfig.go index 92af4d6e..8ce984d2 100644 --- a/src/go/mongolib/proto/replconfig.go +++ b/src/go/mongolib/proto/replconfig.go @@ -40,10 +40,11 @@ type ReplicaSetConfigSettings struct { type ReplicaSetConfig struct { Config struct { - ID string `bson:"_id,omitempty"` // The name of the replica set. Once set, you cannot change the name of a replica set. - Version int64 `bson:"version,omitempty"` // An incrementing number used to distinguish revisions of the replica set configuration object from previous iterations. - Members []*ReplicaSetConfigMember `bson:"members,omitempty"` // An array of member configuration documents, one for each member of the replica set. - Settings *ReplicaSetConfigSettings `bson:"settings,omitempty"` // A document that contains configuration options that apply to the whole replica set. + ID string `bson:"_id,omitempty"` // The name of the replica set. Once set, you cannot change the name of a replica set. + ProtocolVersion int64 `bson:"protocolVersion,omitempty"` // By default, new replica sets in MongoDB 3.2 use protocolVersion: 1. Previous versions of MongoDB use version 0. + Version int64 `bson:"version,omitempty"` // An incrementing number used to distinguish revisions of the replica set configuration object from previous iterations. + Members []*ReplicaSetConfigMember `bson:"members,omitempty"` // An array of member configuration documents, one for each member of the replica set. + Settings *ReplicaSetConfigSettings `bson:"settings,omitempty"` // A document that contains configuration options that apply to the whole replica set. } `bson:"config,omitempty"` // https://docs.mongodb.com/v3.2/reference/replica-configuration/#replica-set-configuration-fields Ok int64 `bson:"ok,omitempty"` }