Beispiel #1
0
        private SDBMessage AdminCommand(string command, BsonDocument arg1, BsonDocument arg2,
                                        BsonDocument arg3, BsonDocument arg4)
        {
            IConnection  connection = sdb.Connection;
            BsonDocument dummyObj   = new BsonDocument();
            SDBMessage   sdbMessage = new SDBMessage();

            sdbMessage.OperationCode = Operation.OP_QUERY;

            // arg1
            if (null == arg1)
            {
                sdbMessage.Matcher = dummyObj;
            }
            else
            {
                sdbMessage.Matcher = arg1;
            }
            // arg2
            if (null == arg2)
            {
                sdbMessage.Selector = dummyObj;
            }
            else
            {
                sdbMessage.Selector = arg2;
            }
            // arg3
            if (null == arg3)
            {
                sdbMessage.OrderBy = dummyObj;
            }
            else
            {
                sdbMessage.OrderBy = arg3;
            }
            // arg4
            if (null == arg4)
            {
                sdbMessage.Hint = dummyObj;
            }
            else
            {
                sdbMessage.Hint = arg4;
            }
            sdbMessage.CollectionFullName = command;
            sdbMessage.Flags           = 0;
            sdbMessage.NodeID          = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID       = 0;
            sdbMessage.SkipRowsCount   = -1;
            sdbMessage.ReturnRowsCount = -1;

            byte[] request = SDBMessageHelper.BuildQueryRequest(sdbMessage, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);

            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            return(rtnSDBMessage);
        }
 internal static SDBMessage CheckRetMsgHeader(SDBMessage sendMsg, SDBMessage rtnMsg)
 {
     uint sendOpCode = (uint)sendMsg.OperationCode;
     uint recvOpCode = (uint)rtnMsg.OperationCode;
     if ((sendOpCode | 0x80000000) != recvOpCode)
         rtnMsg.Flags = (int)Errors.errors.SDB_UNEXPECTED_RESULT;
     return rtnMsg;
 }
        /** \fn          Close()
         * \brief       Close the lob
         * \return void
         * \exception SequoiaDB.BaseException
         * \exception System.Exception
         */
        public void Close()
        {
            /*
             *  /// close reg msg is |MsgOpLob|
             *  struct _MsgHeader
             *  {
             *     SINT32 messageLength ; // total message size, including this
             *     SINT32 opCode ;        // operation code
             *     UINT32 TID ;           // client thead id
             *     MsgRouteID routeID ;   // route id 8 bytes
             *     UINT64 requestID ;     // identifier for this message
             *  } ;
             *
             *  typedef struct _MsgOpLob
             *  {
             *     MsgHeader header ;
             *     INT32 version ;
             *     SINT16 w ;
             *     SINT16 padding ;
             *     SINT32 flags ;
             *     SINT64 contextID ;
             *     UINT32 bsonLen ;
             *  } MsgOpLob ;
             */
            SDBMessage sdbMessage = new SDBMessage();

            // build sdbMessage
            // MsgHeader
            sdbMessage.OperationCode = Operation.MSG_BS_LOB_CLOSE_REQ;
            sdbMessage.NodeID        = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID     = 0;
            // the rest part of _MsgOpLOb
            sdbMessage.Version       = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W             = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding       = (short)0;
            sdbMessage.Flags         = SequoiadbConstants.DEFAULT_FLAGS;
            sdbMessage.ContextIDList = new List <long>();
            sdbMessage.ContextIDList.Add(_contextID);
            sdbMessage.BsonLen = 0;

            // build send msg
            byte[] request = SDBMessageHelper.BuildCloseLobRequest(sdbMessage, _isBigEndian);
            // send msg
            _connection.SendMessage(request);
            // receive and extract return msg from engine
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(_connection.ReceiveMessage(_isBigEndian), _isBigEndian);
            // check the result
            int flags = rtnSDBMessage.Flags;

            if (flags != 0)
            {
                throw new BaseException(flags);
            }
            _isOpen = false;
        }
Beispiel #4
0
        /** \fn void DropCollection(string collectionName)
         *  \brief Remove the named collection of current collection space
         *  \param collectionName The collection name
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public void DropCollection(string collectionName)
        {
            SDBMessage rtn = AdminCommand(SequoiadbConstants.DROP_CMD, SequoiadbConstants.COLLECTION,
                                          name + "." + collectionName);
            int flags = rtn.Flags;

            if (flags != 0)
            {
                throw new BaseException(flags);
            }
        }
Beispiel #5
0
        /** \fn DBCollection CreateCollection(string collectionName)
         *  \brief Create the named collection in current collection space
         *  \param collectionName The collection name
         *  \return The DBCollection handle
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public DBCollection CreateCollection(string collectionName)
        {
            SDBMessage rtn = AdminCommand(SequoiadbConstants.CREATE_CMD, SequoiadbConstants.COLLECTION,
                                          name + "." + collectionName);
            int flags = rtn.Flags;

            if (flags != 0)
            {
                throw new BaseException(flags);
            }

            return(new DBCollection(this, collectionName.Trim()));
        }
        private int _Read(byte[] b)
        {
            SDBMessage sdbMessage = new SDBMessage();

            // MsgHeader
            sdbMessage.OperationCode = Operation.MSG_BS_LOB_READ_REQ;
            sdbMessage.NodeID        = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID     = 0;
            // the rest part of _MsgOpLOb
            sdbMessage.Version       = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W             = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding       = (short)0;
            sdbMessage.Flags         = SequoiadbConstants.DEFAULT_FLAGS;
            sdbMessage.ContextIDList = new List <long>();
            sdbMessage.ContextIDList.Add(_contextID);
            sdbMessage.BsonLen = 0;
            // MsgLobTuple
            sdbMessage.LobLen      = (uint)b.Length;
            sdbMessage.LobSequence = SDB_LOB_DEFAULT_SEQ;
            sdbMessage.LobOffset   = _readOffset;

            // build send msg
            byte[] request = SDBMessageHelper.BuildReadLobRequest(sdbMessage, _isBigEndian);
            // send msg
            _connection.SendMessage(request);

            // receive and extract return msg from engine
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReadLobReply(_connection.ReceiveMessage(_isBigEndian), _isBigEndian);

            // check the result
            int flags   = rtnSDBMessage.Flags;
            int errCode = new BaseException("SDB_DMS_EOC").ErrorCode;

            if (errCode == flags)
            {
                return(-1);
            }
            else if (0 != flags)
            {
                throw new BaseException(flags);
            }
            // return the result
            byte[] lobData = rtnSDBMessage.LobBuff;
            Array.Copy(lobData, b, lobData.Length);

            _readOffset += lobData.Length;
            return(lobData.Length);
        }
        public override DBCursor Query(BsonDocument query, BsonDocument selector, BsonDocument orderBy, BsonDocument hint, long skipRows, long returnRows, int flag)
        {
            BsonDocument dummyObj = new BsonDocument();

            if (query == null)
            {
                query = dummyObj;
            }
            if (selector == null)
            {
                selector = dummyObj;
            }
            if (orderBy == null)
            {
                orderBy = dummyObj;
            }
            if (hint == null)
            {
                hint = dummyObj;
            }
            if (returnRows == 0)
            {
                returnRows = -1;
            }
            if (returnRows == 1)
            {
                flag = flag | DBQuery.FLG_QUERY_WITH_RETURNDATA;
            }
            SDBMessage rtnSDBMessage = AdminCommand(FullName, query, selector,
                                                    orderBy, hint, skipRows, returnRows, flag);

            int flags = rtnSDBMessage.Flags;

            if (flags != 0)
            {
                if (flags == SequoiadbConstants.SDB_DMS_EOC)
                {
                    return(null);
                }
                else
                {
                    throw new BaseException(flags);
                }
            }

            return(new DBCursor <TDocument>(rtnSDBMessage, this));
        }
 internal DBCursor(SDBMessage rtnSDBMessage, Sequoiadb sdb)
 {
     this.connection = sdb.Connection;
     hint            = new BsonDocument();
     hint.Add("", SequoiadbConstants.CLIENT_RECORD_ID_INDEX);
     sdbMessage               = new SDBMessage();
     reqId                    = rtnSDBMessage.RequestID;
     sdbMessage.NodeID        = SequoiadbConstants.ZERO_NODEID;
     sdbMessage.ContextIDList = rtnSDBMessage.ContextIDList;
     contextId                = sdbMessage.ContextIDList[0];
     sdbMessage.NumReturned   = -1;           // return data count
     list         = rtnSDBMessage.ObjectList; // while using fineOne, ObjectList may have data
     hasMore      = true;
     isBigEndian  = sdb.isBigEndian;
     isClosed     = false;
     this.DBQuery = new DBQuery();
 }
 internal DBCursor(SDBMessage rtnSDBMessage, Sequoiadb sdb )
 {
     this.connection = sdb.Connection;
     hint = new BsonDocument();
     hint.Add("", SequoiadbConstants.CLIENT_RECORD_ID_INDEX);
     sdbMessage = new SDBMessage();
     reqId = rtnSDBMessage.RequestID;
     sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
     sdbMessage.ContextIDList = rtnSDBMessage.ContextIDList;
     contextId = sdbMessage.ContextIDList[0];
     sdbMessage.NumReturned = -1;    // return data count
     list = rtnSDBMessage.ObjectList; // while using fineOne, ObjectList may have data
     hasMore = true;
     isBigEndian = sdb.isBigEndian;
     isClosed = false;
     this.DBQuery = new DBQuery();
 }
        /* \fn void UpdateCurrent(BsonDocument modifier)
         *  \brief Update the current Bson of this cursor
         *  \param modifier The updating rule
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */

        /*
         * public void UpdateCurrent(BsonDocument modifier)
         * {
         *  if (modifier == null)
         *      throw new BaseException("SDB_INVALIDARG");
         *  if (dbc == null)
         *      throw new BaseException("SDB_CLT_OBJ_NOT_EXIST");
         *  BsonDocument current;
         *  if (( current = Current()) != null )
         *  {
         *      BsonDocument matcher = new BsonDocument();
         *      matcher.Add(SequoiadbConstants.OID, current[SequoiadbConstants.OID].AsObjectId);
         *      dbc.Update(matcher, modifier, hint);
         *      BsonDocument dummy = new BsonDocument();
         *      list[index] = dbc.Query(matcher, dummy, dummy, dummy).Next();
         *  }
         * }
         */

        /* \fn void DeleteCurrent()
         *  \brief Delete the current Bson of this cursor
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        /*
         * public void DeleteCurrent()
         * {
         *  if ( Current() != null )
         *      dbc.Delete( list[index] );
         *  list.RemoveAt(index);
         *  if (index >= list.Count)
         *      index = -1;
         * }
         */

        private void ReadNextBuffer()
        {
            if (connection == null)
            {
                throw new BaseException("SDB_NOT_CONNECTED");
            }
            if (-1 == contextId)
            {
                hasMore = false;
                index   = -1;
                dbc     = null;
                list    = null;
                return;
            }

            sdbMessage.OperationCode = Operation.OP_GETMORE;
            sdbMessage.RequestID     = reqId;
            byte[] request = SDBMessageHelper.BuildGetMoreRequest(sdbMessage, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);

            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);

            int flags = rtnSDBMessage.Flags;

            if (flags == SequoiadbConstants.SDB_DMS_EOC)
            {
                hasMore = false;
                index   = -1;
                dbc     = null;
                list    = null;
            }
            else if (flags != 0)
            {
                throw new BaseException(flags);
            }
            else
            {
                reqId = rtnSDBMessage.RequestID;
                list  = rtnSDBMessage.ObjectList;
            }
        }
Beispiel #11
0
        /** \fn Node CreateNode(string hostName, int port, string dbpath,
         *                     Dictionary<string, string> map)
         *  \brief Create the replica node
         *  \param hostName The host name of node
         *  \param port The port of node
         *  \param dbpath The database path of node
         *  \param map The other configure information of node
         *  \return The Node object
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public Node CreateNode(string hostName, int port, string dbpath,
                               Dictionary <string, string> map)
        {
            if (hostName == null || port < 0 || port < 0 || port > 65535 ||
                dbpath == null)
            {
                throw new BaseException("SDB_INVALIDARG");
            }
            string command = SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.CREATE_CMD + " "
                             + SequoiadbConstants.NODE;
            BsonDocument configuration = new BsonDocument();

            configuration.Add(SequoiadbConstants.FIELD_GROUPNAME, groupName);
            map.Remove(SequoiadbConstants.FIELD_GROUPNAME);
            configuration.Add(SequoiadbConstants.FIELD_HOSTNAME, hostName);
            map.Remove(SequoiadbConstants.FIELD_HOSTNAME);
            configuration.Add(SequoiadbConstants.SVCNAME, port.ToString());
            map.Remove(SequoiadbConstants.SVCNAME);
            configuration.Add(SequoiadbConstants.DBPATH, dbpath);
            map.Remove(SequoiadbConstants.DBPATH);
            Dictionary <string, string> .Enumerator it = map.GetEnumerator();
            while (it.MoveNext())
            {
                configuration.Add(it.Current.Key, it.Current.Value);
            }
            BsonDocument dummyObj = new BsonDocument();
            SDBMessage   rtn      = AdminCommand(command, configuration, dummyObj, dummyObj, dummyObj);
            int          flags    = rtn.Flags;

            if (flags != 0)
            {
                throw new BaseException(flags);
            }
            else
            {
                return(GetNode(hostName, port));
            }
        }
Beispiel #12
0
        private bool StopStart(bool start)
        {
            string command = start ? SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.ACTIVE_CMD + " "
                             + SequoiadbConstants.GROUP :
                             SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.SHUTDOWN_CMD + " "
                             + SequoiadbConstants.GROUP;
            BsonDocument configuration = new BsonDocument();

            configuration.Add(SequoiadbConstants.FIELD_GROUPNAME, groupName);
            configuration.Add(SequoiadbConstants.FIELD_GROUPID, groupID);
            BsonDocument dummyObj = new BsonDocument();
            SDBMessage   rtn      = AdminCommand(command, configuration, dummyObj, dummyObj, dummyObj);
            int          flags    = rtn.Flags;

            if (flags != 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #13
0
        private bool StopStart(bool start)
        {
            string command = start ? SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.STARTUP_CMD + " "
                             + SequoiadbConstants.NODE :
                             SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.SHUTDOWN_CMD + " "
                             + SequoiadbConstants.NODE;
            BsonDocument configuration = new BsonDocument();

            configuration.Add(SequoiadbConstants.FIELD_HOSTNAME, hostName);
            configuration.Add(SequoiadbConstants.SVCNAME, port.ToString());
            BsonDocument dummyObj = new BsonDocument();
            SDBMessage   rtn      = AdminCommand(command, configuration, dummyObj, dummyObj, dummyObj);
            int          flags    = rtn.Flags;

            if (flags != 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Beispiel #14
0
        /** \fn SDBConst.NodeStatus GetStatus()
         *  \brief Get the status of current node
         *  \return The status of current node
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public SDBConst.NodeStatus GetStatus()
        {
            SDBConst.NodeStatus status = SDBConst.NodeStatus.SDB_NODE_UNKNOWN;
            string command             = SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.SNAP_CMD + " "
                                         + SequoiadbConstants.DATABASE;
            BsonDocument condition = new BsonDocument();
            BsonDocument dummyObj  = new BsonDocument();

            condition.Add(SequoiadbConstants.FIELD_GROUPID, group.GroupID);
            condition.Add(SequoiadbConstants.FIELD_NODEID, nodeID);
            SDBMessage rtn   = AdminCommand(command, condition, dummyObj, dummyObj, dummyObj);
            int        flags = rtn.Flags;

            if (flags == 0)
            {
                status = SDBConst.NodeStatus.SDB_NODE_ACTIVE;
            }
            else if (flags == (int)Errors.errors.SDB_NET_CANNOT_CONNECT)
            {
                status = SDBConst.NodeStatus.SDB_NODE_INACTIVE;
            }

            return(status);
        }
Beispiel #15
0
        /** \fn bool IsCollectionExist(string colName)
         *  \brief Verify the existence of collection in current colleciont space
         *  \param colName The collection name
         *  \return True if collection existed or False if not existed
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public bool IsCollectionExist(string colName)
        {
            string command = SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.TEST_CMD + " "
                             + SequoiadbConstants.COLLECTION;
            BsonDocument condition = new BsonDocument();
            BsonDocument dummyObj  = new BsonDocument();

            condition.Add(SequoiadbConstants.FIELD_NAME, this.name + "." + colName);
            SDBMessage rtn   = AdminCommand(command, condition, dummyObj, dummyObj, dummyObj);
            int        flags = rtn.Flags;

            if (flags == 0)
            {
                return(true);
            }
            else if (flags == (int)Errors.errors.SDB_DMS_NOTEXIST)
            {
                return(false);
            }
            else
            {
                throw new BaseException(flags);
            }
        }
Beispiel #16
0
        /** \fn void RemoveNode(string hostName, int port,
         *             BsonDocument configure)
         *  \brief Remove the specified replica node
         *  \param hostName The host name of node
         *  \param port The port of node
         *  \param configure The configurations for the replica node
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public void RemoveNode(string hostName, int port,
                               BsonDocument configure)
        {
            if (hostName == null || port < 0 || port < 0 || port > 65535)
            {
                throw new BaseException("SDB_INVALIDARG");
            }
            string command = SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.REMOVE_CMD + " "
                             + SequoiadbConstants.NODE;
            BsonDocument config = new BsonDocument();

            config.Add(SequoiadbConstants.FIELD_GROUPNAME, groupName);
            config.Add(SequoiadbConstants.FIELD_HOSTNAME, hostName);
            config.Add(SequoiadbConstants.SVCNAME, Convert.ToString(port));
            if (configure != null)
            {
                foreach (string key in configure.Names)
                {
                    if (key.Equals(SequoiadbConstants.FIELD_GROUPNAME) ||
                        key.Equals(SequoiadbConstants.FIELD_HOSTNAME) ||
                        key.Equals(SequoiadbConstants.SVCNAME))
                    {
                        continue;
                    }
                    config.Add(configure.GetElement(key));
                }
            }
            BsonDocument dummyObj = new BsonDocument();
            SDBMessage   rtn      = AdminCommand(command, config, dummyObj, dummyObj, dummyObj);
            int          flags    = rtn.Flags;

            if (flags != 0)
            {
                throw new BaseException(flags);
            }
        }
        internal static byte[] BuildCloseLobRequest(SDBMessage sdbMessage, bool isBigEndian)
        {
            /*
                /// close reg msg is |MsgOpLob|
                struct _MsgHeader
                {
                   SINT32 messageLength ; // total message size, including this
                   SINT32 opCode ;        // operation code
                   UINT32 TID ;           // client thead id
                   MsgRouteID routeID ;   // route id 8 bytes
                   UINT64 requestID ;     // identifier for this message
                } ;

                typedef struct _MsgOpLob
                {
                   MsgHeader header ;
                   INT32 version ;
                   SINT16 w ;
                   SINT16 padding ;
                   SINT32 flags ;
                   SINT64 contextID ;
                   UINT32 bsonLen ;
                } MsgOpLob ;
             */
            // get info to build _MsgOpLob
            // MsgHeader
            int messageLength = MESSAGE_OPLOB_LENGTH;
            int opCode = (int)sdbMessage.OperationCode;
            byte[] nodeID = sdbMessage.NodeID;
            ulong requestID = sdbMessage.RequestID;
            // the rest part of _MsgOpLOb
            int version = sdbMessage.Version;
            short w = sdbMessage.W;
            short padding = sdbMessage.Padding;
            int flags = sdbMessage.Flags;
            long contextID = sdbMessage.ContextIDList[0];
            uint bsonLen = sdbMessage.BsonLen;

            // build a array list for return
            List<byte[]> fieldList = new List<byte[]>();
            // add MsgHead
            fieldList.Add(AssembleHeader(messageLength, requestID, nodeID, opCode, isBigEndian));
            // add the rest part of MsgOpLob
            ByteBuffer buf = new ByteBuffer(MESSAGE_OPLOB_LENGTH - MESSAGE_HEADER_LENGTH);
            if (isBigEndian)
            {
                buf.IsBigEndian = true;
            }
            buf.PushInt(version);
            buf.PushShort(w);
            buf.PushShort(padding);
            buf.PushInt(flags);
            buf.PushLong(contextID);
            buf.PushInt((int)bsonLen);
            fieldList.Add(buf.ToByteArray());

            // convert to byte array and return
            byte[] msgInByteArray = Helper.ConcatByteArray(fieldList);

            if (logger.IsDebugEnabled)
            {
                StringWriter buff = new StringWriter();
                foreach (byte by in msgInByteArray)
                {
                    buff.Write(string.Format("{0:X}", by));
                }
                logger.Debug("Close Lob Request string==>" + buff.ToString() + "<==");
            }
            return msgInByteArray;
        }
        internal static byte[] BuildWriteLobRequest(SDBMessage sdbMessage, byte[] data, bool isBigEndian)
        {
            /*
                /// write req msg is |MsgOpLob|_MsgLobTuple|data|
                struct _MsgHeader
                {
                   SINT32 messageLength ; // total message size, including this
                   SINT32 opCode ;        // operation code
                   UINT32 TID ;           // client thead id
                   MsgRouteID routeID ;   // route id 8 bytes
                   UINT64 requestID ;     // identifier for this message
                } ;

                typedef struct _MsgOpLob
                {
                   MsgHeader header ;
                   INT32 version ;
                   SINT16 w ;
                   SINT16 padding ;
                   SINT32 flags ;
                   SINT64 contextID ;
                   UINT32 bsonLen ;
                } MsgOpLob ;

                union _MsgLobTuple
                {
                   struct
                   {
                      UINT32 len ;
                      UINT32 sequence ;
                      SINT64 offset ;
                   } columns ;

                   CHAR data[16] ;
                } ;
             */
            // get info to build _MsgOpLob
            // MsgHeader
            int messageLength = 0;
            int opCode = (int)sdbMessage.OperationCode;
            byte[] nodeID = sdbMessage.NodeID;
            ulong requestID = sdbMessage.RequestID;
            // the rest part of _MsgOpLOb
            int version = sdbMessage.Version;
            short w = sdbMessage.W;
            short padding = sdbMessage.Padding;
            int flags = sdbMessage.Flags;
            long contextID = sdbMessage.ContextIDList[0];
            uint bsonLen = sdbMessage.BsonLen;
            // MsgLobTuple
            uint length = sdbMessage.LobLen;
            uint sequence = sdbMessage.LobSequence;
            long offset = sdbMessage.LobOffset;
            // calculate total length
            messageLength = MESSAGE_OPLOB_LENGTH
                            + MESSAGE_LOBTUPLE_LENGTH
                            + Helper.RoundToMultipleXLength(data.Length, 4);
            // build a array list for return
            List<byte[]> fieldList = new List<byte[]>();
            // add MsgHead
            fieldList.Add(AssembleHeader(messageLength, requestID, nodeID, opCode, isBigEndian));
            // add the rest part of MsgOpLob and MsgLobTuple
            ByteBuffer buf = new ByteBuffer(MESSAGE_OPLOB_LENGTH - MESSAGE_HEADER_LENGTH + MESSAGE_LOBTUPLE_LENGTH);
            if (isBigEndian)
            {
                buf.IsBigEndian = true;
            }
            buf.PushInt(version);
            buf.PushShort(w);
            buf.PushShort(padding);
            buf.PushInt(flags);
            buf.PushLong(contextID);
            buf.PushInt((int)bsonLen);

            buf.PushInt((int)length);
            buf.PushInt((int)sequence);
            buf.PushLong(offset);
            // add msg header
            fieldList.Add(buf.ToByteArray());
            // add msg body
            fieldList.Add(Helper.RoundToMultipleX(data, 4));
            // convert to byte array and return
            byte[] msgInByteArray = Helper.ConcatByteArray(fieldList);

            if (logger.IsDebugEnabled)
            {
                StringWriter buff = new StringWriter();
                foreach (byte by in msgInByteArray)
                {
                    buff.Write(string.Format("{0:X}", by));
                }
                logger.Debug("Write Lob Request string==>" + buff.ToString() + "<==");
            }
            return msgInByteArray;
        }
        internal void KillCursor()
        {
            if ((connection == null) || 
                (connection.IsClosed()) || 
                (contextId == -1))
            {
                return;
            }
            SDBMessage sdbMessage = new SDBMessage();
            sdbMessage.OperationCode = Operation.OP_KILL_CONTEXT;
            sdbMessage.ContextIDList = new List<long>();
            sdbMessage.ContextIDList.Add(contextId);
            byte[] request = SDBMessageHelper.BuildKillCursorMsg(sdbMessage, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            int flags = rtnSDBMessage.Flags;
            if (flags != 0)
                throw new BaseException(flags);

            connection = null;
            contextId = -1;
        }
 /** \fn void CloseAllCursors()
  *  \brief Close all the cursors created in current connection, 
  *         we can't use those cursors to get data from db engine again,
  *         but, there are some data cache in local
  *  \return void
  *  \exception SequoiaDB.BaseException
  *  \exception System.Exception
  */
 public void CloseAllCursors()
 {
     // TODO: it's better for us to use DBCursor::Close() to close all the cursor
     SDBMessage sdbMessage = new SDBMessage();
     sdbMessage.OperationCode = Operation.OP_KILL_ALL_CONTEXTS;
     byte[] request = SDBMessageHelper.BuildKillAllContextsRequest(sdbMessage, isBigEndian);
     connection.SendMessage(request);
 }
        /** \fn bool IsValid()
         *  \brief Judge wether the connection is is valid or not
         *  \return If the connection is valid, return true
         */
        public bool IsValid()
        {
            if (connection == null || connection.IsClosed())
            {
                return false;
            }
            int flags = -1;
            // send a lightweight query msg to engine to check
            // wether connection is ok or not
            try
            {
                SDBMessage sdbMessage = new SDBMessage();
                sdbMessage.OperationCode = Operation.OP_KILL_CONTEXT;
                sdbMessage.ContextIDList = new List<long>();
                sdbMessage.ContextIDList.Add(-1);
                byte[] request = SDBMessageHelper.BuildKillCursorMsg(sdbMessage, isBigEndian);

                connection.SendMessage(request);
                SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
                rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
                flags = rtnSDBMessage.Flags;
                if (flags != 0)
                {
                    throw new BaseException(flags);
                }
            }
            catch (System.Exception)
            {
                return false;
            }
            return true;
        }
        internal static byte[] BuildGetMoreRequest(SDBMessage sdbMessage, bool isBigEndian)
        {
            int opCode = (int)sdbMessage.OperationCode;
            ulong requestID = sdbMessage.RequestID;
            long contextId = sdbMessage.ContextIDList[0];
            int numReturned = sdbMessage.NumReturned;
            byte[] nodeID = sdbMessage.NodeID;

            int messageLength = MESSAGE_OPGETMORE_LENGTH;

            List<byte[]> fieldList = new List<byte[]>();
            fieldList.Add(AssembleHeader(messageLength, requestID, nodeID, opCode, isBigEndian));
            ByteBuffer buf = new ByteBuffer(12);
            if (isBigEndian)
                buf.IsBigEndian = true;
            buf.PushLong(contextId);
            buf.PushInt(numReturned);
            fieldList.Add(buf.ToByteArray());

            byte[] msgInByteArray = Helper.ConcatByteArray(fieldList);

            if (logger.IsDebugEnabled)
            {
                StringWriter buff = new StringWriter();
                foreach (byte by in msgInByteArray)
                {
                    buff.Write(string.Format("{0:X}", by));
                }
                logger.Debug("GetMore Request string==>" + buff.ToString() + "<==");
            }

            return msgInByteArray;
        }
 internal static byte[] BuildKillAllContextsRequest(SDBMessage sdbMessage, bool isBigEndian)
 {
     return BuildTransactionRequest(sdbMessage, isBigEndian);
 }
        internal static byte[] BuildTransactionRequest(SDBMessage sdbMessage, bool isBigEndian)
        {
            int opcode = (int)sdbMessage.OperationCode;
            ulong requestID = sdbMessage.RequestID;
            byte[] nodeID = SequoiadbConstants.ZERO_NODEID;
            int messageLength = Helper.RoundToMultipleXLength(MESSAGE_HEADER_LENGTH, 4);

            byte[] msgInByteArray = AssembleHeader(messageLength, requestID, nodeID, (int)opcode, isBigEndian);

            if (logger.IsDebugEnabled)
            {
                StringWriter buff = new StringWriter();
                foreach (byte by in msgInByteArray)
                {
                    buff.Write(string.Format("{0:X}", by));
                }
                logger.Debug("Disconnect Request string==>" + buff.ToString() + "<==");
            }
            return msgInByteArray;
        }
        private SDBMessage CreateCS(string csName, BsonDocument options)
        {
            string commandString = SequoiadbConstants.ADMIN_PROMPT + SequoiadbConstants.CREATE_CMD + " " + SequoiadbConstants.COLSPACE;
            BsonDocument cObj = new BsonDocument();
            BsonDocument dummyObj = new BsonDocument();
            SDBMessage sdbMessage = new SDBMessage();

            cObj.Add(SequoiadbConstants.FIELD_NAME, csName);
            cObj.Add(options);
            sdbMessage.OperationCode = Operation.OP_QUERY;
            sdbMessage.Matcher = cObj;
            sdbMessage.CollectionFullName = commandString;

            sdbMessage.Version = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding = 0;
            sdbMessage.Flags = 0;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID = 0;
            sdbMessage.SkipRowsCount = 0;
            sdbMessage.ReturnRowsCount = -1;
            sdbMessage.Selector = dummyObj;
            sdbMessage.OrderBy = dummyObj;
            sdbMessage.Hint = dummyObj;

            byte[] request = SDBMessageHelper.BuildQueryRequest(sdbMessage, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            return rtnSDBMessage;
        }
        private List<BsonDocument> GetMoreCommand(SDBMessage rtnSDBMessage)
        {
            ulong requestID = rtnSDBMessage.RequestID;
            List<long> contextIDs = rtnSDBMessage.ContextIDList;
            List<BsonDocument> fullList = new List<BsonDocument>();
            bool hasMore = true;
            while (hasMore)
            {
                SDBMessage sdbMessage = new SDBMessage();
                sdbMessage.OperationCode = Operation.OP_GETMORE;
                sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
                sdbMessage.ContextIDList = contextIDs;
                sdbMessage.RequestID = requestID;
                sdbMessage.NumReturned = -1;

                byte[] request = SDBMessageHelper.BuildGetMoreRequest(sdbMessage, isBigEndian);
                connection.SendMessage(request);
                rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
                rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
                int flags = rtnSDBMessage.Flags;
                if (flags != 0)
                {
                    if (flags == SequoiadbConstants.SDB_DMS_EOC)
                        hasMore = false;
                    else
                    {
                        throw new BaseException(flags);
                    }
                }
                else
                {
                    requestID = rtnSDBMessage.RequestID;
                    List<BsonDocument> objList = rtnSDBMessage.ObjectList;
                    fullList.AddRange(objList);
                }
            }
            return fullList;
        }
        /** \fn DBCursor Exec(string sql)
         *  \brief Executing SQL command
         *  \param sql SQL command
         *  \return The DBCursor of matching documents or null
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public DBCursor Exec(string sql)
        {
            SDBMessage sdbMessage = new SDBMessage();
            sdbMessage.OperationCode = Operation.OP_SQL;
            sdbMessage.RequestID = 0;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;

            byte[] request = SDBMessageHelper.BuildSqlMsg(sdbMessage, sql, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            int flags = rtnSDBMessage.Flags;
            if (flags != 0)
            {
                if (flags == SequoiadbConstants.SDB_DMS_EOC)
                    return null;
                else
                {
                    throw new BaseException(flags);
                }
            }
            if (null == rtnSDBMessage.ContextIDList ||
                  rtnSDBMessage.ContextIDList.Count != 1 ||
                  rtnSDBMessage.ContextIDList[0] == -1)
                return null;
            return new DBCursor(rtnSDBMessage, this);
        }
 /** \fn void TransactionRollback()
  *  \brief Rollback the database transaction
  *  \return void
  *  \exception SequoiaDB.BaseException
  *  \exception System.Exception
  */
 public void TransactionRollback()
 {
     SDBMessage sdbMessage = new SDBMessage();
     sdbMessage.OperationCode = Operation.OP_TRANS_ROLLBACK;
     sdbMessage.RequestID = 0;
     byte[] request = SDBMessageHelper.BuildTransactionRequest(sdbMessage, isBigEndian);
     connection.SendMessage(request);
     SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
     rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
     int flags = rtnSDBMessage.Flags;
     if (flags != 0)
         throw new BaseException(flags);
 }
 /** \fn void RemoveUser(string username, string password)
  *  \brief Remove the user from current database
  *  \username Sequoiadb connection user name
  *  \password Sequoiadb connection password
  *  \return void
  *  \exception SequoiaDB.BaseException
  *  \exception System.Exception
  */
 public void RemoveUser(string username, string password)
 {
     if (username == null || password == null)
         throw new BaseException("SDB_INVALIDARG");
     SDBMessage sdbMessage = new SDBMessage();
     sdbMessage.OperationCode = Operation.MSG_AUTH_DELUSR_REQ;
     sdbMessage.RequestID = 0;
     MD5 md5 = MD5.Create();
     byte[] data = md5.ComputeHash(Encoding.Default.GetBytes(password));
     StringBuilder builder = new StringBuilder();
     for (int i = 0; i < data.Length; i++)
         builder.Append(data[i].ToString("x2"));
     byte[] request = SDBMessageHelper.BuildAuthDelMsg(sdbMessage, username, builder.ToString(), isBigEndian);
     connection.SendMessage(request);
     SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
     rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
     int flags = rtnSDBMessage.Flags;
     if (flags != 0)
         throw new BaseException(flags);
 }
Beispiel #30
0
        private int _Read(byte[] b)
        {
            SDBMessage sdbMessage = new SDBMessage();
            // MsgHeader
            sdbMessage.OperationCode = Operation.MSG_BS_LOB_READ_REQ;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID = 0;
            // the rest part of _MsgOpLOb
            sdbMessage.Version = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding = (short)0;
            sdbMessage.Flags = SequoiadbConstants.DEFAULT_FLAGS;
            sdbMessage.ContextIDList = new List<long>();
            sdbMessage.ContextIDList.Add(_contextID);
            sdbMessage.BsonLen = 0;
            // MsgLobTuple
            sdbMessage.LobLen = (uint)b.Length;
            sdbMessage.LobSequence = SDB_LOB_DEFAULT_SEQ;
            sdbMessage.LobOffset = _readOffset;

            // build send msg
            byte[] request = SDBMessageHelper.BuildReadLobRequest(sdbMessage, _isBigEndian);
            // send msg
            _connection.SendMessage(request);

            // receive and extract return msg from engine
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReadLobReply(_connection.ReceiveMessage(_isBigEndian), _isBigEndian);

            // check the result
            int flags = rtnSDBMessage.Flags;
            int errCode = new BaseException("SDB_DMS_EOC").ErrorCode;
            if ( errCode == flags)
            {
                return -1;
            }
            else if (0 != flags)
            {
                throw new BaseException(flags);
            }
            // return the result
            byte[] lobData = rtnSDBMessage.LobBuff;
            Array.Copy(lobData, b, lobData.Length);

            _readOffset += lobData.Length;
            return lobData.Length;
        }
        internal static byte[] BuildQueryRequest(SDBMessage sdbMessage, bool isBigEndian)
        {
            int opCode = (int)sdbMessage.OperationCode;
            string collectionName = sdbMessage.CollectionFullName;
            int version = sdbMessage.Version;
            short w = sdbMessage.W;
            short padding = sdbMessage.Padding;
            int flags = sdbMessage.Flags;
            ulong requestID = sdbMessage.RequestID;
            long skipRowsCount = sdbMessage.SkipRowsCount;
            long returnRowsCount = sdbMessage.ReturnRowsCount;
            byte[] collByteArray = System.Text.Encoding.UTF8.GetBytes(collectionName);
            int collectionNameLength = collByteArray.Length;

            byte[] query = sdbMessage.Matcher.ToBson();
            byte[] fieldSelector = sdbMessage.Selector.ToBson();
            byte[] orderBy = sdbMessage.OrderBy.ToBson();
            byte[] hint = sdbMessage.Hint.ToBson();
            byte[] nodeID = sdbMessage.NodeID;
            if (isBigEndian)
            {
                BsonEndianConvert(query, 0, query.Length, true);
                BsonEndianConvert(fieldSelector, 0, fieldSelector.Length, true);
                BsonEndianConvert(orderBy, 0, orderBy.Length, true);
                BsonEndianConvert(hint, 0, hint.Length, true);
            }

            int messageLength = Helper.RoundToMultipleXLength(
                MESSAGE_OPQUERY_LENGTH + collectionNameLength, 4)
                + Helper.RoundToMultipleXLength(query.Length, 4)
                + Helper.RoundToMultipleXLength(fieldSelector.Length, 4)
                + Helper.RoundToMultipleXLength(orderBy.Length, 4)
                + Helper.RoundToMultipleXLength(hint.Length, 4);

            List<byte[]> fieldList = new List<byte[]>();
            fieldList.Add(AssembleHeader(messageLength, requestID, nodeID, opCode, isBigEndian));
            ByteBuffer buf = new ByteBuffer(32);
            if (isBigEndian)
                buf.IsBigEndian = true;
            buf.PushInt(version);
            buf.PushShort(w);
            buf.PushShort(padding);
            buf.PushInt(flags);
            buf.PushInt(collectionNameLength);
            buf.PushLong(skipRowsCount);
            buf.PushLong(returnRowsCount);

            fieldList.Add(buf.ToByteArray());

            byte[] newCollectionName = new byte[collectionNameLength + 1];
            for (int i = 0; i < collectionNameLength; i++)
                newCollectionName[i] = collByteArray[i];

            fieldList.Add(Helper.RoundToMultipleX(newCollectionName, 4));
            fieldList.Add(Helper.RoundToMultipleX(query, 4));
            fieldList.Add(Helper.RoundToMultipleX(fieldSelector, 4));
            fieldList.Add(Helper.RoundToMultipleX(orderBy, 4));
            fieldList.Add(Helper.RoundToMultipleX(hint, 4));

            byte[] msgInByteArray = Helper.ConcatByteArray(fieldList);

            if (logger.IsDebugEnabled) {
               StringWriter buff = new StringWriter();
               foreach (byte by in msgInByteArray) {
                  buff.Write(string.Format("{0:X}", by));
               }
               logger.Debug("Query Request string==>" + buff.ToString() + "<==");
            }
            return msgInByteArray;
        }
        internal static byte[] BuildSqlMsg(SDBMessage sdbMessage, string sql, bool isBigEndian)
        {
            int opCode = (int)sdbMessage.OperationCode;
            ulong requestID = sdbMessage.RequestID;
            byte[] nodeID = sdbMessage.NodeID;
            byte[] sqlBytes = System.Text.Encoding.UTF8.GetBytes(sql);
            int sqlLen = sqlBytes.Length+1;
            int messageLength = Helper.RoundToMultipleXLength(
                MESSAGE_HEADER_LENGTH + sqlLen, 4);

            List<byte[]> fieldList = new List<byte[]>();
            fieldList.Add(AssembleHeader(messageLength, requestID, nodeID, opCode, isBigEndian));
            byte[] newArray = new byte[sqlLen];
            for (int i = 0; i < sqlLen - 1; i++)
                newArray[i] = sqlBytes[i];

            fieldList.Add(Helper.RoundToMultipleX(newArray, 4));

            byte[] msgInByteArray = Helper.ConcatByteArray(fieldList);

            if (logger.IsDebugEnabled)
            {
                StringWriter buff = new StringWriter();
                foreach (byte by in msgInByteArray)
                {
                    buff.Write(string.Format("{0:X}", by));
                }
                logger.Debug("SQL Message string==>" + buff.ToString() + "<==");
            }
            return msgInByteArray;
        }
	    internal static byte[] BuildAggrRequest(SDBMessage sdbMessage, bool isBigEndian)
        {
            int opCode = (int)sdbMessage.OperationCode;
            string collectionName = sdbMessage.CollectionFullName;
            int version = sdbMessage.Version;
            short w = sdbMessage.W;
            short padding = sdbMessage.Padding;
            int flags = sdbMessage.Flags;
            ulong requestID = sdbMessage.RequestID;
            byte[] collByteArray = System.Text.Encoding.UTF8.GetBytes(collectionName);
            int collectionNameLength = collByteArray.Length;

            byte[] insertor = sdbMessage.Insertor.ToBson();
            byte[] nodeID = sdbMessage.NodeID;

            if (isBigEndian)
            {
                BsonEndianConvert(insertor, 0, insertor.Length, true);
            }

            int messageLength = Helper.RoundToMultipleXLength(
                MESSAGE_OPINSERT_LENGTH + collectionNameLength, 4)
                + Helper.RoundToMultipleXLength(insertor.Length, 4);

            List<byte[]> fieldList = new List<byte[]>();
            fieldList.Add(AssembleHeader(messageLength, requestID, nodeID, opCode, isBigEndian));
            ByteBuffer buf = new ByteBuffer(16);
            if (isBigEndian)
                buf.IsBigEndian = true;
            buf.PushInt(version);
            buf.PushShort(w);
            buf.PushShort(padding);
            buf.PushInt(flags);
            buf.PushInt(collectionNameLength);

            fieldList.Add(buf.ToByteArray());

            byte[] newCollectionName = new byte[collectionNameLength + 1];
            for (int i = 0; i < collectionNameLength; i++)
                newCollectionName[i] = collByteArray[i];

            fieldList.Add(Helper.RoundToMultipleX(newCollectionName, 4));
            fieldList.Add(Helper.RoundToMultipleX(insertor, 4));

            byte[] msgInByteArray = Helper.ConcatByteArray(fieldList);

            if (logger.IsDebugEnabled)
            {
                StringWriter buff = new StringWriter();
                foreach (byte by in msgInByteArray)
                {
                    buff.Write(string.Format("{0:X}", by));
                }
                logger.Debug("Aggregate Request string==>" + buff.ToString() + "<==");
            }
            return msgInByteArray;
        }
Beispiel #34
0
        private void _Open()
        {
            /*
             *  /// open reg msg is |MsgOpLob|bsonobj|
             *  struct _MsgHeader
             *  {
             *     SINT32 messageLength ; // total message size, including this
             *     SINT32 opCode ;        // operation code
             *     UINT32 TID ;           // client thead id
             *     MsgRouteID routeID ;   // route id 8 bytes
             *     UINT64 requestID ;     // identifier for this message
             *  } ;
             *
             *  typedef struct _MsgOpLob
             *  {
             *     MsgHeader header ;
             *     INT32 version ;
             *     SINT16 w ;
             *     SINT16 padding ;
             *     SINT32 flags ;
             *     SINT64 contextID ;
             *     UINT32 bsonLen ;
             *  } MsgOpLob ;
             */
            // add info into object
            BsonDocument openLob = new BsonDocument();

            openLob.Add(SequoiadbConstants.FIELD_COLLECTION, _cl.FullName);
            openLob.Add(SequoiadbConstants.FIELD_LOB_OID, _id);
            openLob.Add(SequoiadbConstants.FIELD_LOB_OPEN_MODE, _mode);

            SDBMessage sdbMessage = new SDBMessage();

            // build sdbMessage
            // MsgHeader
            sdbMessage.OperationCode = Operation.MSG_BS_LOB_OPEN_REQ;
            sdbMessage.NodeID        = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID     = 0;
            // the rest part of _MsgOpLOb
            sdbMessage.Version       = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W             = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding       = (short)0;
            sdbMessage.Flags         = SequoiadbConstants.DEFAULT_FLAGS;
            sdbMessage.ContextIDList = new List <long>();
            sdbMessage.ContextIDList.Add(SequoiadbConstants.DEFAULT_CONTEXTID);
            sdbMessage.Matcher = openLob;
            // build send msg
            byte[] request = SDBMessageHelper.BuildOpenLobRequest(sdbMessage, _isBigEndian);
            // send msg
            _connection.SendMessage(request);
            // receive and extract return msg from engine
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(_connection.ReceiveMessage(_isBigEndian), _isBigEndian);
            // check the result
            int flags = rtnSDBMessage.Flags;

            if (flags != 0)
            {
                throw new BaseException(flags);
            }
            // get lob info return from engine
            List <BsonDocument> objList = rtnSDBMessage.ObjectList;
            BsonDocument        obj     = objList[0];

            if (null == obj)
            {
                throw new BaseException("SDB_SYS");
            }
            // lob size
            if (obj.Contains(SequoiadbConstants.FIELD_LOB_SIZE) && obj[SequoiadbConstants.FIELD_LOB_SIZE].IsInt64)
            {
                _size = obj[SequoiadbConstants.FIELD_LOB_SIZE].AsInt64;
            }
            else
            {
                throw new BaseException("SDB_SYS");
            }
            // lob create time
            if (obj.Contains(SequoiadbConstants.FIELD_LOB_CREATTIME) && obj[SequoiadbConstants.FIELD_LOB_CREATTIME].IsInt64)
            {
                _createTime = obj[SequoiadbConstants.FIELD_LOB_CREATTIME].AsInt64;
            }
            else
            {
                throw new BaseException("SDB_SYS");
            }
            // contextID
            _contextID = rtnSDBMessage.ContextIDList[0];
        }
        internal static byte[] BuildAuthDelMsg(SDBMessage sdbMessage, string username, string passwd, bool isBigEndian)
        {
            ulong requestID = sdbMessage.RequestID;
            int opCode = (int)sdbMessage.OperationCode;
            byte[] nodeID = SequoiadbConstants.ZERO_NODEID;
            BsonDocument auth = new BsonDocument();
            auth.Add(SequoiadbConstants.SDB_AUTH_USER, username);
            auth.Add(SequoiadbConstants.SDB_AUTH_PASSWD, passwd);
            byte[] authbyte = auth.ToBson();
            if (isBigEndian)
            {
                BsonEndianConvert(authbyte, 0, authbyte.Length, true);
            }

            int messageLength = MESSAGE_HEADER_LENGTH + Helper.RoundToMultipleXLength(
                                authbyte.Length, 4);

            List<byte[]> fieldList = new List<byte[]>();
            fieldList.Add(AssembleHeader(messageLength, requestID, nodeID,
                                         opCode, isBigEndian));

            fieldList.Add(Helper.RoundToMultipleX(authbyte, 4));

            byte[] msgInByteArray = Helper.ConcatByteArray(fieldList);

            if (logger.IsDebugEnabled)
            {
                StringWriter buff = new StringWriter();
                foreach (byte by in msgInByteArray)
                {
                    buff.Write(string.Format("{0:X}", by));
                }
                logger.Debug("SQL Message string==>" + buff.ToString() + "<==");
            }
            return msgInByteArray;
        }
 private void Auth()
 {
     SDBMessage sdbMessage = new SDBMessage();
     sdbMessage.OperationCode = Operation.MSG_AUTH_VERIFY_REQ;
     sdbMessage.RequestID = 0;
     MD5 md5 = MD5.Create();
     byte[] data = md5.ComputeHash(Encoding.Default.GetBytes(password));
     StringBuilder builder = new StringBuilder();
     for (int i = 0; i < data.Length; i++)
         builder.Append(data[i].ToString("x2"));
     byte[] request = SDBMessageHelper.BuildAuthMsg(sdbMessage, userName, builder.ToString(), isBigEndian);
     connection.SendMessage(request);
     SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
     rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
     int flags = rtnSDBMessage.Flags;
     if (flags != 0)
         throw new BaseException(flags);
 }
Beispiel #37
0
        private SDBMessage AdminCommand(string command, BsonDocument arg1, BsonDocument arg2,
                                        BsonDocument arg3, BsonDocument arg4)
        {
            IConnection connection = group.SequoiaDB.Connection;
            BsonDocument dummyObj = new BsonDocument();
            SDBMessage sdbMessage = new SDBMessage();
            sdbMessage.OperationCode = Operation.OP_QUERY;
            sdbMessage.Matcher = arg1;
            sdbMessage.Selector = arg2;
            sdbMessage.OrderBy = arg3;
            sdbMessage.Hint = arg4;
            // arg1
            if (null == arg1)
            {
                sdbMessage.Matcher = dummyObj;
            }
            else
            {
                sdbMessage.Matcher = arg1;
            }
            // arg2
            if (null == arg2)
            {
                sdbMessage.Selector = dummyObj;
            }
            else
            {
                sdbMessage.Selector = arg2;
            }
            // arg3
            if (null == arg3)
            {
                sdbMessage.OrderBy = dummyObj;
            }
            else
            {
                sdbMessage.OrderBy = arg3;
            }
            // arg4
            if (null == arg4)
            {
                sdbMessage.Hint = dummyObj;
            }
            else
            {
                sdbMessage.Hint = arg4;
            }
            sdbMessage.CollectionFullName = command;
            sdbMessage.Flags = 0;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID = 0;
            sdbMessage.SkipRowsCount = -1;
            sdbMessage.ReturnRowsCount = -1;

            byte[] request = SDBMessageHelper.BuildQueryRequest(sdbMessage, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            return rtnSDBMessage;
        }
Beispiel #38
0
        /** \fn          Write( byte[] b )
         *  \brief       Writes b.length bytes from the specified 
         *               byte array to this lob. 
         *  \param       b   the data.
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public void Write(byte[] b)
        {
            /*
                /// write req msg is |MsgOpLob|_MsgLobTuple|data|
                struct _MsgHeader
                {
                   SINT32 messageLength ; // total message size, including this
                   SINT32 opCode ;        // operation code
                   UINT32 TID ;           // client thead id
                   MsgRouteID routeID ;   // route id 8 bytes
                   UINT64 requestID ;     // identifier for this message
                } ;

                typedef struct _MsgOpLob
                {
                   MsgHeader header ;
                   INT32 version ;
                   SINT16 w ;
                   SINT16 padding ;
                   SINT32 flags ;
                   SINT64 contextID ;
                   UINT32 bsonLen ;
                } MsgOpLob ;

                union _MsgLobTuple
                {
                   struct
                   {
                      UINT32 len ;
                      UINT32 sequence ;
                      SINT64 offset ;
                   } columns ;

                   CHAR data[16] ;
                } ;
             */
            SDBMessage sdbMessage = new SDBMessage();
            // MsgHeader
            sdbMessage.OperationCode = Operation.MSG_BS_LOB_WRITE_REQ;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID = 0;
            // the rest part of _MsgOpLOb
            sdbMessage.Version = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding = (short)0;
            sdbMessage.Flags = SequoiadbConstants.DEFAULT_FLAGS;
            sdbMessage.ContextIDList = new List<long>();
            sdbMessage.ContextIDList.Add(_contextID);
            sdbMessage.BsonLen = 0;
            // MsgLobTuple
            sdbMessage.LobLen = (uint)b.Length;
            sdbMessage.LobSequence = SDB_LOB_DEFAULT_SEQ;
            sdbMessage.LobOffset = SDB_LOB_DEFAULT_OFFSET;

            // build send msg
            byte[] request = SDBMessageHelper.BuildWriteLobRequest(sdbMessage, b, _isBigEndian);
            // send msg
            _connection.SendMessage(request);

            // receive and extract return msg from engine
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(_connection.ReceiveMessage(_isBigEndian), _isBigEndian);

            // check the result
            int flags = rtnSDBMessage.Flags;
            if (0 != flags)
            {
                throw new BaseException(flags);
            }
            // keep to total number for query
            _size += b.Length;
        }
        /** \fn void ExecUpdate(string sql)
         *  \brief Executing SQL command for updating
         *  \param sql SQL command
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public void ExecUpdate(string sql)
        {
            SDBMessage sdbMessage = new SDBMessage();
            sdbMessage.OperationCode = Operation.OP_SQL;
            sdbMessage.RequestID = 0;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;

            byte[] request = SDBMessageHelper.BuildSqlMsg(sdbMessage, sql, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            int flags = rtnSDBMessage.Flags;
            if (flags != 0)
                throw new BaseException(flags);
        }
        internal static byte[] BuildKillCursorMsg(SDBMessage sdbMessage, bool isBigEndian)
        {
            int opCode = (int)sdbMessage.OperationCode;
            List<long> contextIDs = sdbMessage.ContextIDList;
            ulong requestID = 0;
            byte[] nodeID = SequoiadbConstants.ZERO_NODEID;
            int lenContextIDs = sizeof(long) * contextIDs.Count;
            int messageLength = MESSAGE_KILLCURSOR_LENGTH + lenContextIDs;

            List<byte[]> fieldList = new List<byte[]>();
            fieldList.Add(AssembleHeader(messageLength, requestID, nodeID, opCode, isBigEndian));
            ByteBuffer buf = new ByteBuffer(8 + lenContextIDs);
            if (isBigEndian)
                buf.IsBigEndian = true;
            int zero = 0;
            int numContexts = 1;
            buf.PushInt(zero);
            buf.PushInt(numContexts);
            foreach (long contextID in contextIDs)
                buf.PushLong(contextID);

            fieldList.Add(buf.ToByteArray());
            byte[] msgInByteArray = Helper.ConcatByteArray(fieldList);

            if (logger.IsDebugEnabled)
            {
                StringWriter buff = new StringWriter();
                foreach (byte by in msgInByteArray)
                {
                    buff.Write(string.Format("{0:X}", by));
                }
                logger.Debug("Disconnect Request string==>" + buff.ToString() + "<==");
            }
            return msgInByteArray;
        }
Beispiel #41
0
        private SDBMessage AdminCommand(string command, BsonDocument matcher, BsonDocument selector,
                                        BsonDocument orderBy, BsonDocument hint)
        {
            BsonDocument dummyObj   = new BsonDocument();
            IConnection  connection = sdb.Connection;
            SDBMessage   sdbMessage = new SDBMessage();

            sdbMessage.OperationCode      = Operation.OP_QUERY;
            sdbMessage.CollectionFullName = command;
            sdbMessage.Version            = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W               = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding         = 0;
            sdbMessage.Flags           = 0;
            sdbMessage.NodeID          = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID       = 0;
            sdbMessage.SkipRowsCount   = 0;
            sdbMessage.ReturnRowsCount = -1;
            // matcher
            if (null == matcher)
            {
                sdbMessage.Matcher = dummyObj;
            }
            else
            {
                sdbMessage.Matcher = matcher;
            }
            // selector
            if (null == selector)
            {
                sdbMessage.Selector = dummyObj;
            }
            else
            {
                sdbMessage.Selector = selector;
            }
            // orderBy
            if (null == orderBy)
            {
                sdbMessage.OrderBy = dummyObj;
            }
            else
            {
                sdbMessage.OrderBy = orderBy;
            }
            // hint
            if (null == hint)
            {
                sdbMessage.Hint = dummyObj;
            }
            else
            {
                sdbMessage.Hint = hint;
            }

            byte[] request = SDBMessageHelper.BuildQueryRequest(sdbMessage, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);

            rtnMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnMessage);
            return(rtnMessage);
        }
Beispiel #42
0
        private SDBMessage AdminCommand(string cmdType, string contextType, string contextName)
        {
            IConnection connection = sdb.Connection;
            BsonDocument dummyObj = new BsonDocument();
            SDBMessage sdbMessage = new SDBMessage();
            string commandString = SequoiadbConstants.ADMIN_PROMPT + cmdType + " " + contextType;

            BsonDocument cObj = new BsonDocument();
            cObj.Add(SequoiadbConstants.FIELD_NAME, contextName);
            sdbMessage.OperationCode = Operation.OP_QUERY;
            sdbMessage.Matcher = cObj;
            sdbMessage.CollectionFullName = commandString;
            sdbMessage.Flags = 0;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID = 0;
            sdbMessage.SkipRowsCount = -1;
            sdbMessage.ReturnRowsCount = -1;
            sdbMessage.Selector = dummyObj;
            sdbMessage.OrderBy = dummyObj;
            sdbMessage.Hint = dummyObj;

            byte[] request = SDBMessageHelper.BuildQueryRequest(sdbMessage, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            return rtnSDBMessage;
        }
Beispiel #43
0
        /** \fn          Close()
          * \brief       Close the lob
          * \return void
          * \exception SequoiaDB.BaseException
          * \exception System.Exception
          */
        public void Close()
        {
            /*
                /// close reg msg is |MsgOpLob|
                struct _MsgHeader
                {
                   SINT32 messageLength ; // total message size, including this
                   SINT32 opCode ;        // operation code
                   UINT32 TID ;           // client thead id
                   MsgRouteID routeID ;   // route id 8 bytes
                   UINT64 requestID ;     // identifier for this message
                } ;

                typedef struct _MsgOpLob
                {
                   MsgHeader header ;
                   INT32 version ;
                   SINT16 w ;
                   SINT16 padding ;
                   SINT32 flags ;
                   SINT64 contextID ;
                   UINT32 bsonLen ;
                } MsgOpLob ;
             */
            SDBMessage sdbMessage = new SDBMessage();
            // build sdbMessage
            // MsgHeader
            sdbMessage.OperationCode = Operation.MSG_BS_LOB_CLOSE_REQ;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID = 0;
            // the rest part of _MsgOpLOb
            sdbMessage.Version = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding = (short)0;
            sdbMessage.Flags = SequoiadbConstants.DEFAULT_FLAGS;
            sdbMessage.ContextIDList = new List<long>();
            sdbMessage.ContextIDList.Add(_contextID);
            sdbMessage.BsonLen = 0;

            // build send msg
            byte[] request = SDBMessageHelper.BuildCloseLobRequest(sdbMessage, _isBigEndian);
            // send msg
            _connection.SendMessage(request);
            // receive and extract return msg from engine
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(_connection.ReceiveMessage(_isBigEndian), _isBigEndian);
            // check the result
            int flags = rtnSDBMessage.Flags;
            if (flags != 0)
            {
                throw new BaseException(flags);
            }
            _isOpen = false;
        }
Beispiel #44
0
        private SDBMessage AdminCommand(string command, BsonDocument matcher, BsonDocument selector,
                                        BsonDocument orderBy, BsonDocument hint)
        {
            BsonDocument dummyObj = new BsonDocument();
            IConnection connection = sdb.Connection;
            SDBMessage sdbMessage = new SDBMessage();
            sdbMessage.OperationCode = Operation.OP_QUERY;
            sdbMessage.CollectionFullName = command;
            sdbMessage.Version = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding = 0;
            sdbMessage.Flags = 0;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID = 0;
            sdbMessage.SkipRowsCount = 0;
            sdbMessage.ReturnRowsCount = -1;
            // matcher
            if (null == matcher)
            {
                sdbMessage.Matcher = dummyObj;
            }
            else
            {
                sdbMessage.Matcher = matcher;
            }
            // selector
            if (null == selector)
            {
                sdbMessage.Selector = dummyObj;
            }
            else
            {
                sdbMessage.Selector = selector;
            }
            // orderBy
            if (null == orderBy)
            {
                sdbMessage.OrderBy = dummyObj;
            }
            else
            {
                sdbMessage.OrderBy = orderBy;
            }
            // hint
            if (null == hint)
            {
                sdbMessage.Hint = dummyObj;
            }
            else
            {
                sdbMessage.Hint = hint;
            }

            byte[] request = SDBMessageHelper.BuildQueryRequest(sdbMessage, isBigEndian);
            connection.SendMessage(request);
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(connection.ReceiveMessage(isBigEndian), isBigEndian);
            rtnSDBMessage = SDBMessageHelper.CheckRetMsgHeader(sdbMessage, rtnSDBMessage);
            return rtnSDBMessage;
        }
Beispiel #45
0
        private void _Open()
        {
            /*
                /// open reg msg is |MsgOpLob|bsonobj|
                struct _MsgHeader
                {
                   SINT32 messageLength ; // total message size, including this
                   SINT32 opCode ;        // operation code
                   UINT32 TID ;           // client thead id
                   MsgRouteID routeID ;   // route id 8 bytes
                   UINT64 requestID ;     // identifier for this message
                } ;

                typedef struct _MsgOpLob
                {
                   MsgHeader header ;
                   INT32 version ;
                   SINT16 w ;
                   SINT16 padding ;
                   SINT32 flags ;
                   SINT64 contextID ;
                   UINT32 bsonLen ;
                } MsgOpLob ;
             */
            // add info into object
            BsonDocument openLob = new BsonDocument();
            openLob.Add(SequoiadbConstants.FIELD_COLLECTION, _cl.FullName);
            openLob.Add(SequoiadbConstants.FIELD_LOB_OID, _id);
            openLob.Add(SequoiadbConstants.FIELD_LOB_OPEN_MODE, _mode);

            SDBMessage sdbMessage = new SDBMessage();
            // build sdbMessage
            // MsgHeader
            sdbMessage.OperationCode = Operation.MSG_BS_LOB_OPEN_REQ;
            sdbMessage.NodeID = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID = 0;
            // the rest part of _MsgOpLOb
            sdbMessage.Version = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding = (short)0;
            sdbMessage.Flags = SequoiadbConstants.DEFAULT_FLAGS;
            sdbMessage.ContextIDList = new List<long>();
            sdbMessage.ContextIDList.Add(SequoiadbConstants.DEFAULT_CONTEXTID);
            sdbMessage.Matcher = openLob;
            // build send msg
            byte[] request = SDBMessageHelper.BuildOpenLobRequest( sdbMessage, _isBigEndian);
            // send msg
            _connection.SendMessage(request);
            // receive and extract return msg from engine
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(_connection.ReceiveMessage(_isBigEndian), _isBigEndian);
            // check the result
            int flags = rtnSDBMessage.Flags;
            if (flags != 0)
            {
                throw new BaseException(flags);
            }
            // get lob info return from engine
            List<BsonDocument> objList = rtnSDBMessage.ObjectList;
            BsonDocument obj = objList[0];
            if (null == obj)
            {
                throw new BaseException("SDB_SYS");
            }
            // lob size
            if (obj.Contains(SequoiadbConstants.FIELD_LOB_SIZE) && obj[SequoiadbConstants.FIELD_LOB_SIZE].IsInt64)
            {
                _size = obj[SequoiadbConstants.FIELD_LOB_SIZE].AsInt64;
            }
            else
            {
                throw new BaseException("SDB_SYS");
            }
            // lob create time
            if (obj.Contains(SequoiadbConstants.FIELD_LOB_CREATTIME) && obj[SequoiadbConstants.FIELD_LOB_CREATTIME].IsInt64)
            {
                _createTime = obj[SequoiadbConstants.FIELD_LOB_CREATTIME].AsInt64;
            }
            else
            {
                throw new BaseException("SDB_SYS");
            }
            // contextID
            _contextID = rtnSDBMessage.ContextIDList[0];
        }
Beispiel #46
0
        /** \fn          Write( byte[] b )
         *  \brief       Writes b.length bytes from the specified
         *               byte array to this lob.
         *  \param       b   the data.
         *  \exception SequoiaDB.BaseException
         *  \exception System.Exception
         */
        public void Write(byte[] b)
        {
            /*
             *  /// write req msg is |MsgOpLob|_MsgLobTuple|data|
             *  struct _MsgHeader
             *  {
             *     SINT32 messageLength ; // total message size, including this
             *     SINT32 opCode ;        // operation code
             *     UINT32 TID ;           // client thead id
             *     MsgRouteID routeID ;   // route id 8 bytes
             *     UINT64 requestID ;     // identifier for this message
             *  } ;
             *
             *  typedef struct _MsgOpLob
             *  {
             *     MsgHeader header ;
             *     INT32 version ;
             *     SINT16 w ;
             *     SINT16 padding ;
             *     SINT32 flags ;
             *     SINT64 contextID ;
             *     UINT32 bsonLen ;
             *  } MsgOpLob ;
             *
             *  union _MsgLobTuple
             *  {
             *     struct
             *     {
             *        UINT32 len ;
             *        UINT32 sequence ;
             *        SINT64 offset ;
             *     } columns ;
             *
             *     CHAR data[16] ;
             *  } ;
             */
            SDBMessage sdbMessage = new SDBMessage();

            // MsgHeader
            sdbMessage.OperationCode = Operation.MSG_BS_LOB_WRITE_REQ;
            sdbMessage.NodeID        = SequoiadbConstants.ZERO_NODEID;
            sdbMessage.RequestID     = 0;
            // the rest part of _MsgOpLOb
            sdbMessage.Version       = SequoiadbConstants.DEFAULT_VERSION;
            sdbMessage.W             = SequoiadbConstants.DEFAULT_W;
            sdbMessage.Padding       = (short)0;
            sdbMessage.Flags         = SequoiadbConstants.DEFAULT_FLAGS;
            sdbMessage.ContextIDList = new List <long>();
            sdbMessage.ContextIDList.Add(_contextID);
            sdbMessage.BsonLen = 0;
            // MsgLobTuple
            sdbMessage.LobLen      = (uint)b.Length;
            sdbMessage.LobSequence = SDB_LOB_DEFAULT_SEQ;
            sdbMessage.LobOffset   = SDB_LOB_DEFAULT_OFFSET;

            // build send msg
            byte[] request = SDBMessageHelper.BuildWriteLobRequest(sdbMessage, b, _isBigEndian);
            // send msg
            _connection.SendMessage(request);

            // receive and extract return msg from engine
            SDBMessage rtnSDBMessage = SDBMessageHelper.MsgExtractReply(_connection.ReceiveMessage(_isBigEndian), _isBigEndian);

            // check the result
            int flags = rtnSDBMessage.Flags;

            if (0 != flags)
            {
                throw new BaseException(flags);
            }
            // keep to total number for query
            _size += b.Length;
        }
 internal DBCursor(SDBMessage rtnSDBMessage, DBCollection dbc)
     : base(rtnSDBMessage, dbc)
 {
     this.m_Enumerator = new DBCursorEnumerator <TDocument>(this);
 }
        private static void ExtractHeader(SDBMessage sdbMessage, byte[] header, bool isBigEndian)
        {
            List<byte[]> tmp = Helper.SplitByteArray(header, 4);
            byte[] msgLength = tmp[0];
            byte[] remainning = tmp[1];
            sdbMessage.RequestLength = Helper.ByteToInt(msgLength, isBigEndian);

            tmp = Helper.SplitByteArray(remainning, 4);
            byte[] opCode = tmp[0];
            remainning = tmp[1];
            sdbMessage.OperationCode = (Operation)Helper.ByteToInt(opCode, isBigEndian);

            tmp = Helper.SplitByteArray(remainning, 12);
            byte[] nodeID = tmp[0];
            remainning = tmp[1];
            sdbMessage.NodeID = nodeID;
            sdbMessage.RequestID = (ulong)Helper.ByteToLong(remainning, isBigEndian); 
        }