Permalink
Browse files

Added ReplicaSet support

You can create one via:
    mongo.ReplicaSet.New( 'rsname', { 'host1:port1', 'host2:port2' } )

In doing this, refactored all the common client methods to use DBClientBase rather than DBClientConnection.  Basically, a ton of stuff was moved from mongo_connection.cpp to mongo_dbclient.cpp with search/replace of DBClientConnection/DBClientBase and connection/dbclient.  No other functional changes were made to these functions, except that they dispatch to a new function userdata_to_dbclient.

Once that refactoring was done, adding ReplicaSet as a new top-level class was relatively straight-forward.
  • Loading branch information...
1 parent ae8d9c9 commit 90e2fdf491e005f33026e04c4a03e5b3c61db46f @neomantra neomantra committed Jul 30, 2011
Showing with 896 additions and 681 deletions.
  1. +5 −1 Makefile
  2. +10 −4 common.h
  3. +2 −0 main.cpp
  4. +8 −669 mongo_connection.cpp
  5. +1 −1 mongo_cursor.cpp
  6. +735 −0 mongo_dbclient.cpp
  7. +3 −6 mongo_gridfs.cpp
  8. +132 −0 mongo_replicaset.cpp
View
@@ -8,7 +8,7 @@ OUTLIB=mongo.so
LDFLAGS= $(LIBS)
-OBJS = main.o mongo_bsontypes.o mongo_connection.o mongo_cursor.o mongo_gridfile.o mongo_gridfs.o mongo_gridfschunk.o mongo_query.o utils.o
+OBJS = main.o mongo_bsontypes.o mongo_dbclient.o mongo_replicaset.o mongo_connection.o mongo_cursor.o mongo_gridfile.o mongo_gridfs.o mongo_gridfschunk.o mongo_query.o utils.o
all: luamongo
@@ -31,6 +31,8 @@ echo:
main.o: main.cpp utils.h
$(CC) -c -o $@ $< $(CFLAGS)
+mongo_dbclient.o: mongo_dbclient.cpp common.h utils.h
+ $(CC) -c -o $@ $< $(CFLAGS)
mongo_connection.o: mongo_connection.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_cursor.o: mongo_cursor.cpp common.h utils.h
@@ -43,6 +45,8 @@ mongo_gridfschunk.o: mongo_gridfschunk.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_query.o: mongo_query.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
+mongo_replicaset.o: mongo_replicaset.cpp common.h utils.h
+ $(CC) -c -o $@ $< $(CFLAGS)
mongo_bsontypes.o: mongo_bsontypes.cpp common.h
$(CC) -c -o $@ $< $(CFLAGS)
utils.o: utils.cpp common.h utils.h
View
@@ -1,12 +1,17 @@
-#define LUAMONGO_ROOT "mongo"
-#define LUAMONGO_CONNECTION "mongo.Connection"
-#define LUAMONGO_CURSOR "mongo.Cursor"
-#define LUAMONGO_QUERY "mongo.Query"
+#define LUAMONGO_ROOT "mongo"
+#define LUAMONGO_CONNECTION "mongo.Connection"
+#define LUAMONGO_REPLICASET "mongo.ReplicaSet"
+#define LUAMONGO_CURSOR "mongo.Cursor"
+#define LUAMONGO_QUERY "mongo.Query"
#define LUAMONGO_GRIDFS "mongo.GridFS"
#define LUAMONGO_GRIDFILE "mongo.GridFile"
#define LUAMONGO_GRIDFSCHUNK "mongo.GridFSChunk"
+// not an actual class, pseudo-base for error messages
+#define LUAMONGO_DBCLIENT "mongo.DBClient"
+
#define LUAMONGO_ERR_CONNECTION_FAILED "Connection failed: %s"
+#define LUAMONGO_ERR_REPLICASET_FAILED "ReplicaSet.New failed: %s"
#define LUAMONGO_ERR_GRIDFS_FAILED "GridFS failed: %s"
#define LUAMONGO_ERR_GRIDFSCHUNK_FAILED "GridFSChunk failed: %s"
#define LUAMONGO_ERR_QUERY_FAILED "Query failed: %s"
@@ -27,3 +32,4 @@
#else
#define CHUNK GridFSChunk
#endif
+
View
@@ -38,6 +38,7 @@ extern "C" {
extern int mongo_bsontypes_register(lua_State *L);
extern int mongo_connection_register(lua_State *L);
+extern int mongo_replicaset_register(lua_State *L);
extern int mongo_cursor_register(lua_State *L);
extern int mongo_query_register(lua_State *L);
extern int mongo_gridfs_register(lua_State *L);
@@ -55,6 +56,7 @@ extern "C" {
LM_EXPORT int luaopen_mongo(lua_State *L) {
mongo_bsontypes_register(L);
mongo_connection_register(L);
+ mongo_replicaset_register(L);
mongo_cursor_register(L);
mongo_query_register(L);
Oops, something went wrong.

0 comments on commit 90e2fdf

Please sign in to comment.