summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2017-05-02 18:34:22 -0400
committerBenety Goh <benety@mongodb.com>2017-05-04 10:04:27 -0400
commitda8feef15c25d10c084f846b70912cdc1956ed47 (patch)
treea709e99c20f5bafc782e1c55af5919301834cb7a
parent4b76e2cd5a49a64d0ba9789d800b61de90032274 (diff)
downloadmongo-da8feef15c25d10c084f846b70912cdc1956ed47.tar.gz
SERVER-28218 add IDL support to OpTime
-rw-r--r--src/mongo/db/repl/optime.cpp5
-rw-r--r--src/mongo/db/repl/optime.h8
-rw-r--r--src/mongo/db/repl/replication_types.idl43
3 files changed, 56 insertions, 0 deletions
diff --git a/src/mongo/db/repl/optime.cpp b/src/mongo/db/repl/optime.cpp
index b722f692aaa..aa033d34bab 100644
--- a/src/mongo/db/repl/optime.cpp
+++ b/src/mongo/db/repl/optime.cpp
@@ -71,6 +71,11 @@ BSONObj OpTime::toBSON() const {
return bldr.obj();
}
+// static
+OpTime OpTime::parse(const BSONObj& obj) {
+ return uassertStatusOK(parseFromOplogEntry(obj));
+}
+
std::string OpTime::toString() const {
return toBSON().toString();
}
diff --git a/src/mongo/db/repl/optime.h b/src/mongo/db/repl/optime.h
index a15bd87fc0c..3028b42c642 100644
--- a/src/mongo/db/repl/optime.h
+++ b/src/mongo/db/repl/optime.h
@@ -87,6 +87,14 @@ public:
static StatusWith<OpTime> parseFromOplogEntry(const BSONObj& obj);
+ /**
+ * Parses OpTime from a document in the form:
+ * { ts: <timestamp>, t: <term> }
+ *
+ * Throws an exception on error.
+ */
+ static OpTime parse(const BSONObj& obj);
+
std::string toString() const;
// Returns true when this OpTime is not yet initialized.
diff --git a/src/mongo/db/repl/replication_types.idl b/src/mongo/db/repl/replication_types.idl
new file mode 100644
index 00000000000..8ad3fd6e730
--- /dev/null
+++ b/src/mongo/db/repl/replication_types.idl
@@ -0,0 +1,43 @@
+# Copyright (C) 2017 MongoDB Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License, version 3,
+# as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception, the copyright holders give permission to link the
+# code of portions of this program with the OpenSSL library under certain
+# conditions as described in each individual source file and distribute
+# linked combinations including the program with the OpenSSL library. You
+# must comply with the GNU Affero General Public License in all respects for
+# all of the code used other than as permitted herein. If you modify file(s)
+# with this exception, you may extend this exception to your version of the
+# file(s), but you are not obligated to do so. If you do not wish to do so,
+# delete this exception statement from your version. If you delete this
+# exception statement from all source files in the program, then also delete
+# it in the license file.
+
+# Replication IDL File
+
+global:
+ cpp_namespace: "mongo::repl"
+ cpp_includes:
+ - "mongo/db/repl/optime.h"
+
+imports:
+ - "mongo/idl/basic_types.idl"
+
+types:
+ optime:
+ bson_serialization_type: object
+ description: A document representing an OpTime.
+ cpp_type: "OpTime"
+ serializer: OpTime::toBSON
+ deserializer: OpTime::parse