Exemple #1
0
        internal RemoteStorage(AvailabilityGroup trinityServer, int connPerServer, MemoryCloud mc, int serverId, bool nonblocking)
        {
            this.memory_cloud = mc;
            this.MyServerId   = serverId;
            retry             = 3;

            var connect_async_task = Task.Factory.StartNew(() =>
            {
                for (int k = 0; k < connPerServer; k++) // make different server connections interleaved
                {
                    for (int i = 0; i < trinityServer.ServerInstances.Count; i++)
                    {
                        ConnectIPEndPoint(trinityServer.ServerInstances[i].EndPoint);
                    }
                }
                BackgroundThread.AddBackgroundTask(new BackgroundTask(Heartbeat, TrinityConfig.HeartbeatInterval));
                mc.ReportServerConnectedEvent(serverId);
            });

            if (!nonblocking)
            {
                try { connect_async_task.Wait(); }
                catch (AggregateException ex) { ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); }
            }
        }
        protected internal RemoteStorage(IEnumerable <ServerInfo> servers, int connPerServer, MemoryCloud mc, int partitionId, bool nonblocking)
        {
            this.m_memorycloud = mc;
            this.PartitionId   = partitionId;

            var connect_async_task = Task.Factory.StartNew(() =>
            {
                for (int k = 0; k < connPerServer; k++) // make different server connections interleaved
                {
                    foreach (var s in servers)
                    {
                        Connect(s);
                    }
                }
                if (mc != null && partitionId != -1)
                {
                    BackgroundThread.AddBackgroundTask(new BackgroundTask(Heartbeat, TrinityConfig.HeartbeatInterval));
                    mc.ReportServerConnectedEvent(this);
                }
            });

            if (!nonblocking)
            {
                try { connect_async_task.Wait(); }
                catch (AggregateException ex) { ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); }
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds a new cell to the key-value store if the cell Id does not exist, or updates an existing cell in the key-value store if the cell Id already exists.
        /// Note that the generic cell will be saved as a strongly typed cell. It can then be loaded into either a strongly-typed cell or a generic cell.
        /// </summary>
        /// <param name="storage">A <see cref="Trinity.Storage.MemoryCloud"/> instance.</param>
        /// <param name="cell">The cell to be saved.</param>

        public void SaveGenericCell(Trinity.Storage.MemoryCloud storage, ICell cell)
        {
            switch ((CellType)cell.CellType)
            {
            /*FOREACH*/
            case CellType.t_cell_name:
                storage.Savet_cell_name((t_cell_name)cell);
                break;
                /*END*/
            }
        }
Exemple #4
0
        public unsafe static void ReportToMyProxy(this Trinity.Storage.MemoryCloud storage, int proxyId, ResultWriter msg)
        {
            byte *bufferPtr = (byte *)msg.handle.AddrOfPinnedObject().ToPointer();

            *(int *)(bufferPtr) = msg.Length + TrinityProtocol.ProtocolHeaderLength;
            *(bufferPtr + TrinityProtocol.MsgTypeOffset) = (byte)TrinityMessageType.ASYNC;
            *(bufferPtr + TrinityProtocol.MsgIdOffset)   = (byte)Trinity.TSL.TrinityProxy.MyProxy.AsynReqMessageType.Report;
            Global.GetProxy(proxyId).SendMessage(
                msg.buffer,
                0,
                msg.Length + TrinityProtocol.AsyncRequestWithoutResponseHeaderLength);
        }
Exemple #5
0
 public unsafe static SSSPCell LoadSSSPCell(this Trinity.Storage.MemoryCloud storage, long CellID)
 {
     byte[] content = Global.CloudStorage.LoadCell(CellID);
     fixed(byte *ptr = content)
     {
         using (var cell = new SSSPCell_Accessor(ptr))
         {
             SSSPCell ret = cell;
             ret.CellID = CellID;
             return(ret);
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Adds a new cell to the key-value store if the cell Id does not exist, or updates an existing cell in the key-value store if the cell Id already exists.
        /// Note that the generic cell will be saved as a strongly typed cell. It can then be loaded into either a strongly-typed cell or a generic cell.
        /// </summary>
        /// <param name="storage">A <see cref="Trinity.Storage.MemoryCloud"/> instance.</param>
        /// <param name="cell">The cell to be saved.</param>
        public void SaveGenericCell(Trinity.Storage.MemoryCloud storage, ICell cell)
        {
            switch ((CellType)cell.CellType)
            {
            case CellType.Movie:
                storage.SaveMovie((Movie)cell);
                break;

            case CellType.Celebrity:
                storage.SaveCelebrity((Celebrity)cell);
                break;
            }
        }
Exemple #7
0
        public unsafe static void DistanceUpdatingToSSSPSlave(this Trinity.Storage.MemoryCloud storage, int slaveId, DistanceUpdatingMessageWriter msg)
        {
            byte *bufferPtr = (byte *)msg.handle.AddrOfPinnedObject().ToPointer();

            *(int *)(bufferPtr) = msg.Length + TrinityProtocol.ProtocolHeaderLength;
            *(bufferPtr + TrinityProtocol.MsgTypeOffset) = (byte)TrinityMessageType.ASYNC;
            *(bufferPtr + TrinityProtocol.MsgIdOffset)   = (byte)Trinity.TSL.TrinitySlave.SSSPSlave.AsynReqMessageType.DistanceUpdating;
            Global.CloudStorage.SendMessage(
                slaveId,
                msg.buffer,
                0,
                msg.Length + TrinityProtocol.AsyncRequestWithoutResponseHeaderLength);
        }
Exemple #8
0
        /// <summary>
        /// Loads the content of the cell with the specified cell Id.
        /// </summary>
        /// <param name="storage">A <see cref="Trinity.Storage.MemoryCloud"/> instance.</param>
        /// <param name="cellId">A 64-bit cell Id.</param>
        /// <returns></returns>
        public unsafe ICell LoadGenericCell(Trinity.Storage.MemoryCloud storage, long cellId)
        {
            ushort type;

            byte[] buff;
            var    err = storage.LoadCell(cellId, out buff, out type);

            if (err != TrinityErrorCode.E_SUCCESS)
            {
                switch (err)
                {
                case TrinityErrorCode.E_CELL_NOT_FOUND:
                    throw new CellNotFoundException("Cannot access the cell.");

                case TrinityErrorCode.E_NETWORK_SEND_FAILURE:
                    throw new System.IO.IOException("Network error while accessing the cell.");

                default:
                    throw new Exception("Cannot access the cell. Error code: " + err.ToString());
                }
            }
            switch ((CellType)type)
            {
            case CellType.Movie:
                fixed(byte *Movie_ptr = buff)
                {
                    Movie_Accessor /*_*/ Movie_accessor = new Movie_Accessor(Movie_ptr);

                    Movie_accessor.CellID = cellId;
                    return((Movie)Movie_accessor);
                }

                break;

            case CellType.Celebrity:
                fixed(byte *Celebrity_ptr = buff)
                {
                    Celebrity_Accessor /*_*/ Celebrity_accessor = new Celebrity_Accessor(Celebrity_ptr);

                    Celebrity_accessor.CellID = cellId;
                    return((Celebrity)Celebrity_accessor);
                }

                break;

            default:
                throw new CellTypeNotMatchException("Cannot determine cell type.");
            }
        }
Exemple #9
0
        public unsafe static ResultReader QueryToMyProxy(this Trinity.Storage.MemoryCloud storage, int proxyId, NameRequestWriter msg)
        {
            byte *bufferPtr = (byte *)msg.handle.AddrOfPinnedObject().ToPointer();

            *(int *)(bufferPtr) = msg.Length + TrinityProtocol.ProtocolHeaderLength;
            *(bufferPtr + TrinityProtocol.MsgTypeOffset) = (byte)TrinityMessageType.SYNC_WITH_RSP;
            *(bufferPtr + TrinityProtocol.MsgIdOffset)   = (byte)Trinity.TSL.TrinityProxy.MyProxy.SynReqRspMessageType.Query;
            TrinityMessage response;

            Global.GetProxy(proxyId).SendMessage(
                msg.buffer,
                0,
                msg.Length + TrinityProtocol.MsgHeader, out response);
            return(new ResultReader(response.Buffer, TrinityMessage.Offset));
        }
Exemple #10
0
        public unsafe static bool SaveSSSPCell(this Trinity.Storage.MemoryCloud storage, long CellID, int distance = default(int), long parent = default(long), List <long> neighbors = null)
        {
            byte *targetPtr = null;

            targetPtr += 4;
            targetPtr += 8;

            if (neighbors != null)
            {
                targetPtr += neighbors.Count * 8 + sizeof(int);
            }
            else
            {
                targetPtr += sizeof(int);
            }


            byte[] tmpcell = new byte[(int)(targetPtr)];
            fixed(byte *tmpcellptr = tmpcell)
            {
                targetPtr          = tmpcellptr;
                *(int *)targetPtr  = distance;
                targetPtr         += 4;
                *(long *)targetPtr = parent;
                targetPtr         += 8;

                if (neighbors != null)
                {
                    *(int *)targetPtr = neighbors.Count * 8;
                    targetPtr        += sizeof(int);
                    for (int iterator_0 = 0; iterator_0 < neighbors.Count; ++iterator_0)
                    {
                        *(long *)targetPtr = neighbors[iterator_0];
                        targetPtr         += 8;
                    }
                }
                else
                {
                    *(int *)targetPtr = 0;
                    targetPtr        += sizeof(int);
                }
            }

            return(storage.SaveCell(CellID, tmpcell, (ushort)CellType.SSSPCell));
        }
Exemple #11
0
 public unsafe static bool SaveSSSPCell(this Trinity.Storage.MemoryCloud storage, SSSPCell CellContent)
 {
     return(SaveSSSPCell(storage, CellContent.CellID, CellContent.distance, CellContent.parent, CellContent.neighbors));
 }
Exemple #12
0
 public unsafe static bool Savenode(this Trinity.Storage.MemoryCloud storage, node CellContent)
 {
     return(Savenode(storage, CellContent.CellID, CellContent.name, CellContent.friends));
 }
Exemple #13
0
        public unsafe static bool Savenode(this Trinity.Storage.MemoryCloud storage, long CellID, string name = null, List <long> friends = null)
        {
            byte *targetPtr = null;

            if (name != null)
            {
                targetPtr += name.Length * 2 + sizeof(int);
            }
            else
            {
                targetPtr += sizeof(int);
            }

            if (friends != null)
            {
                targetPtr += friends.Count * 8 + sizeof(int);
            }
            else
            {
                targetPtr += sizeof(int);
            }


            byte[] tmpcell = new byte[(int)(targetPtr)];
            fixed(byte *tmpcellptr = tmpcell)
            {
                targetPtr = tmpcellptr;

                if (name != null)
                {
                    *(int *)targetPtr = name.Length * 2;
                    targetPtr        += sizeof(int);
                    for (int iterator_0 = 0; iterator_0 < name.Length; ++iterator_0)
                    {
                        *(char *)targetPtr = name[iterator_0];
                        targetPtr         += 2;
                    }
                }
                else
                {
                    *(int *)targetPtr = 0;
                    targetPtr        += sizeof(int);
                }

                if (friends != null)
                {
                    *(int *)targetPtr = friends.Count * 8;
                    targetPtr        += sizeof(int);
                    for (int iterator_0 = 0; iterator_0 < friends.Count; ++iterator_0)
                    {
                        *(long *)targetPtr = friends[iterator_0];
                        targetPtr         += 8;
                    }
                }
                else
                {
                    *(int *)targetPtr = 0;
                    targetPtr        += sizeof(int);
                }
            }

            return(storage.SaveCell(CellID, tmpcell, (ushort)CellType.node));
        }
Exemple #14
0
 public void SaveGenericCell(MemoryCloud storage, ICell cell)
 {
     throw new NotImplementedException();
 }
Exemple #15
0
 public ICell LoadGenericCell(MemoryCloud storage, long cellId)
 {
     throw new NotImplementedException();
 }