public T Read <T>(JsonOperationContext context) where T : class { using (_disposerLock.EnsureNotDisposed()) using ( var json = context.Sync.ParseToMemory(_stream, "rachis-item", BlittableJsonDocumentBuilder.UsageMode.None, _buffer)) { json.BlittableValidation(); ValidateMessage(typeof(T).Name, json); return(JsonDeserializationRachis <T> .Deserialize(json)); } }
public RachisHello InitFollower(JsonOperationContext context) { using (_disposerLock.EnsureNotDisposed()) using ( var json = context.Sync.ParseToMemory(_stream, "rachis-initial-msg", BlittableJsonDocumentBuilder.UsageMode.None, _buffer)) { json.BlittableValidation(); ValidateMessage(nameof(RachisHello), json); var rachisHello = JsonDeserializationRachis <RachisHello> .Deserialize(json); _src = rachisHello.DebugSourceIdentifier ?? "unknown"; _destTag = rachisHello.DebugDestinationIdentifier ?? _destTag; _log = LoggingSource.Instance.GetLogger <RemoteConnection>($"{_src} > {_destTag}"); _info.Destination = _destTag; return(rachisHello); } }
private async Task <bool> DispatchServerWideTcpConnection(TcpConnectionOptions tcp, TcpConnectionHeaderMessage header) { tcp.Operation = header.Operation; if (tcp.Operation == TcpConnectionHeaderMessage.OperationTypes.Cluster) { ServerStore.ClusterAcceptNewConnection(tcp.Stream); return(true); } if (tcp.Operation == TcpConnectionHeaderMessage.OperationTypes.Heartbeats) { // check for the term using (_tcpContextPool.AllocateOperationContext(out JsonOperationContext context)) using (var headerJson = await context.ParseToMemoryAsync( tcp.Stream, "maintenance-heartbeat-header", BlittableJsonDocumentBuilder.UsageMode.None, tcp.PinnedBuffer )) { var maintenanceHeader = JsonDeserializationRachis <ClusterMaintenanceSupervisor.ClusterMaintenanceConnectionHeader> .Deserialize(headerJson); if (_clusterMaintenanceWorker?.CurrentTerm > maintenanceHeader.Term) { if (_tcpLogger.IsInfoEnabled) { _tcpLogger.Info($"Request for maintenance with term {maintenanceHeader.Term} was rejected, " + $"because we are already connected to the recent leader with the term {_clusterMaintenanceWorker.CurrentTerm}"); } tcp.Dispose(); return(true); } var old = _clusterMaintenanceWorker; using (old) { _clusterMaintenanceWorker = new ClusterMaintenanceWorker(tcp, ServerStore.ServerShutdown, ServerStore, maintenanceHeader.Term); _clusterMaintenanceWorker.Start(); } return(true); } } return(false); }
public RachisEntry ReadRachisEntry(JsonOperationContext context) { // we explicitly not disposing this here, because we need to access the entry BlittableJsonReaderObject json = null; try { using (_disposerLock.EnsureNotDisposed()) { json = context.Sync.ParseToMemory(_stream, "rachis-entry", BlittableJsonDocumentBuilder.UsageMode.None, _buffer); json.BlittableValidation(); ValidateMessage(nameof(RachisEntry), json); return(JsonDeserializationRachis <RachisEntry> .Deserialize(json)); } } catch { json?.Dispose(); throw; } }