public void RaiseNotifications(IndexChange indexChange) { OnIndexChange?.Invoke(indexChange); foreach (var connection in Connections) { connection.Value.SendIndexChanges(indexChange); } }
public void SendIndexChanges(IndexChange change) { if (_watchAllIndexes > 0) { Send(change); return; } if (change.Name != null && _matchingIndexes.Contains(change.Name)) { Send(change); } }
public bool AddIndexChange(Index target, Index.CHANGE change) { IndexChange newChange = new IndexChange(target, change); if (allChanges.Contains(newChange)) { Global.Methods.PrintError("This index change was added previously: " + newChange); return(false); } allChanges.Add(newChange); Global.Methods.PrintInfo("New value change added: " + newChange); return(true); }
private void AddIndexIfNecessary(IndexChange change) { if (change.Type != IndexChangeTypes.IndexAdded) { return; } Task.Factory.StartNew(async() => { await _locker.WaitAsync(); try { if (_loadedIndexes.ContainsKey(change.Name)) { return; } var database = await _databaseLandlord.TryGetOrCreateResourceStore(_databaseName); using (database.ServerStore.ContextPool.AllocateOperationContext(out TransactionOperationContext context)) { context.OpenReadTransaction(); var mapping = GetIndexMapping(context, database.ServerStore, database.Name); if (mapping.ContainsKey(change.Name) == false) { context.CloseTransaction(); var result = await database.ServerStore.SendToLeaderAsync(new UpdateSnmpDatabaseIndexesMappingCommand(_databaseName, new List <string> { change.Name }, RaftIdGenerator.NewId())); await database.ServerStore.Cluster.WaitForIndexNotification(result.Index); context.OpenReadTransaction(); mapping = GetIndexMapping(context, database.ServerStore, database.Name); } LoadIndex(change.Name, (int)mapping[change.Name]); } } finally { _locker.Release(); } }); }
private void Send(IndexChange change) { var value = new DynamicJsonValue { ["Type"] = nameof(IndexChange), ["Value"] = change.ToJson() }; if (_disposeToken.IsCancellationRequested == false) { _sendQueue.Enqueue(new ChangeValue { ValueToSend = value, AllowSkip = change.Type == IndexChangeTypes.BatchCompleted }); } }
private void OnIndexChange(IndexChange change) { IndexAndPerformanceStatsList indexAndPerformanceStats; switch (change.Type) { case IndexChangeTypes.IndexRemoved: _perIndexStats.TryRemove(change.Name, out indexAndPerformanceStats); return; case IndexChangeTypes.Renamed: var indexRenameChange = change as IndexRenameChange; Debug.Assert(indexRenameChange != null); _perIndexStats.TryRemove(indexRenameChange.OldIndexName, out indexAndPerformanceStats); break; } if (change.Type != IndexChangeTypes.BatchCompleted && change.Type != IndexChangeTypes.IndexPaused) { return; } if (_perIndexStats.TryGetValue(change.Name, out indexAndPerformanceStats) == false) { var index = Database.IndexStore.GetIndex(change.Name); if (index == null) { return; } indexAndPerformanceStats = new IndexAndPerformanceStatsList(change.Name); _perIndexStats.TryAdd(change.Name, indexAndPerformanceStats); } var indexInstance = Database.IndexStore.GetIndex(indexAndPerformanceStats.Handler); var latestStat = indexInstance?.GetLatestIndexingStat(); if (latestStat != null) { indexAndPerformanceStats.Performance.Add(latestStat); } }