/// <summary> /// Creates the associated <see cref="DataStore" /> for new cacheable type /// </summary> /// <param name="request"></param> /// <param name="client"></param> private void RegisterType(RegisterTypeRequest request, IClient client) { try { var typeDescription = request.CollectionSchema; var collectionName = typeDescription.CollectionName; var dataStore = DataStores.TryGetValue(collectionName); if (ShardCount == 0) // not initialized { ShardIndex = request.ShardIndex; ShardCount = request.ShardsInCluster; } else // check it didn't change { if (ShardIndex != request.ShardIndex || ShardCount != request.ShardsInCluster) { throw new NotSupportedException( $"Cluster configuration changed. This node was shard {ShardIndex} / {ShardCount} and now is {request.ShardIndex} / {request.ShardsInCluster}"); } } if (dataStore != null) //type already registered { //if the type description changed reindex if (!typeDescription.Equals(dataStore.CollectionSchema)) { var newDataStore = DataStore.Reindex(dataStore, typeDescription); DataStores[collectionName] = newDataStore; _serviceContainer.SchemaPersistence.SaveSchema(GenerateSchema()); } } else // new type, store it in the type dictionary and initialize its DataStore { var newDataStore = new DataStore(typeDescription, new NullEvictionPolicy(), _serviceContainer.NodeConfig.FullTextConfig); DataStores.Add(collectionName, newDataStore); _serviceContainer.SchemaPersistence.SaveSchema(GenerateSchema()); } client?.SendResponse(new NullResponse()); } catch (Exception e) { client?.SendResponse(new ExceptionResponse(e)); } }
private void ProcessDataRequest(DataRequest dataRequest, IClient client) { // the collection name is case insensitive var key = DataStores.Keys.FirstOrDefault(k => dataRequest.CollectionName.ToLower() == k.ToLower()); DataStore dataStore = null; if (key != null) { dataStore = DataStores.TryGetValue(key); } else { // for now there is one special table containing the activity log. It is always non persistent and it has an LRU eviction policy if (dataRequest.CollectionName.ToLower() == "@activity") { dataStore = _serviceContainer.Log.ActivityTable; } } if (dataStore == null) { throw new NotSupportedException("Unknown collection : " + dataRequest.CollectionName); } Dbg.Trace($"begin processing {dataRequest.AccessType} request on server {ShardIndex}"); var lockManager = _serviceContainer.LockManager; if (dataRequest.AccessType == DataAccessType.Write) { if (dataRequest is DomainDeclarationRequest) { if (PersistenceEngine != null) { throw new NotSupportedException( "Domain declaration can only be used in cache mode (without persistence)"); } } if (dataRequest is EvictionSetupRequest) { if (PersistenceEngine != null) { throw new NotSupportedException( "Eviction can only be used in cache mode (without persistence)"); } } lockManager.DoWithWriteLock(() => { if (dataRequest is RemoveManyRequest removeManyRequest) { var mgr = new DeleteManager(dataStore, PersistenceEngine); mgr.ProcessRequest(removeManyRequest, client); } else if (dataRequest is PutRequest putRequest) { var mgr = new PutManager(PersistenceEngine, _serviceContainer.FeedSessionManager, dataStore, _serviceContainer.Log); mgr.ProcessRequest(putRequest, client); } else if (dataRequest is DomainDeclarationRequest domainDeclarationRequest) { var mgr = new CacheOnlyManager(dataStore); mgr.ProcessRequest(domainDeclarationRequest, client); } else if (dataRequest is EvictionSetupRequest evictionSetupRequest) { var mgr = new CacheOnlyManager(dataStore); mgr.ProcessRequest(evictionSetupRequest, client); } }, dataRequest.CollectionName); } else { if (dataRequest.SessionId != default)// request inside a consistent read context { if (lockManager.CheckLock(dataRequest.SessionId, false, dataRequest.CollectionName)) { if (dataRequest is GetRequest getRequest) { new QueryManager(dataStore, _serviceContainer.Log).ProcessRequest(getRequest, client); } else if (dataRequest is EvalRequest evalRequest) { new QueryManager(dataStore).ProcessRequest(evalRequest, client); } else if (dataRequest is PivotRequest pivotRequest) { new QueryManager(dataStore).ProcessRequest(pivotRequest, client); } } else { throw new NotSupportedException("Data request with session received but no session is active"); } } else // simple request { lockManager.DoWithReadLock(() => { if (dataRequest is GetRequest getRequest) { new QueryManager(dataStore, _serviceContainer.Log).ProcessRequest(getRequest, client); } else if (dataRequest is EvalRequest evalRequest) { new QueryManager(dataStore).ProcessRequest(evalRequest, client); } else if (dataRequest is PivotRequest pivotRequest) { new QueryManager(dataStore).ProcessRequest(pivotRequest, client); } }, dataRequest.CollectionName); } } Dbg.Trace($"end processing {dataRequest.AccessType} request on server {ShardIndex}"); }
public DataStore TryGetByName(string name) { return(DataStores.TryGetValue(name)); }