public async Task Dispose() { _status = IndexStatus.Disposed; //get all silos Dictionary <SiloAddress, SiloStatus> hosts = await SiloUtils.GetHosts(true); var numHosts = hosts.Keys.Count; Task[] disposeToSilos = new Task[numHosts]; int i = 0; IList <IOrleansQueryResultStream <V> > result = new List <IOrleansQueryResultStream <V> >(); GrainId grainID = GetGrainID(IndexUtils.GetIndexNameFromIndexGrain(this)); foreach (SiloAddress siloAddress in hosts.Keys) { //dispose the index on each silo disposeToSilos[i] = InsideRuntimeClient.Current.InternalGrainFactory.GetSystemTarget <ActiveHashIndexPartitionedPerSiloBucket>( grainID, siloAddress ).Dispose(); ++i; } await Task.WhenAll(disposeToSilos); }
public Task <V> LookupUnique(K key) { if (!(state.IndexStatus == IndexStatus.Available)) { var e = new Exception(string.Format("Index is not still available.")); logger.Error(IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainServiceBucket3, $"ParentIndex {_parentIndexName}: {e.Message}", e); throw e; } if (state.IndexMap.TryGetValue(key, out HashIndexSingleBucketEntry <V> entry) && !entry.IsTentative) { if (entry.Values.Count() == 1) { return(Task.FromResult(entry.Values.GetEnumerator().Current)); } var e = new Exception(string.Format("There are {0} values for the unique lookup key \"{1}\" does not exist on index \"{2}->{3}\".", entry.Values.Count(), key, _parentIndexName, IndexUtils.GetIndexNameFromIndexGrain(this))); logger.Error(IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainServiceBucket4, $"ParentIndex {_parentIndexName}: {e.Message}", e); throw e; } var ex = new Exception(string.Format("The lookup key \"{0}\" does not exist on index \"{1}->{2}\".", key, _parentIndexName, IndexUtils.GetIndexNameFromIndexGrain(this))); logger.Error(IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainServiceBucket5, $"ParentIndex {_parentIndexName}: {ex.Message}", ex); throw ex; }
public override Task OnActivateAsync() { var indexName = IndexUtils.GetIndexNameFromIndexGrain(this); _indexedField = indexName.Substring(2); return(base.OnActivateAsync()); }
public override Task OnActivateAsync() { _indexName = IndexUtils.GetIndexNameFromIndexGrain(this); _indexedField = _indexName.Substring(2); //_isUnique = isUniqueIndex; //TODO: missing support for the uniqueness feature return(base.OnActivateAsync()); }
public async Task Dispose() { _status = IndexStatus.Disposed; var indexName = IndexUtils.GetIndexNameFromIndexGrain(this); GrainReference makeGrainReference(SiloAddress siloAddress) => GetGrainReference(this.SiloIndexManager, indexName, siloAddress); // Get and Dispose() all buckets in silos Dictionary <SiloAddress, SiloStatus> hosts = await this.SiloIndexManager.GetSiloHosts(true); await Task.WhenAll(hosts.Keys.Select(sa => this.SiloIndexManager.GetGrainService <IActiveHashIndexPartitionedPerSiloBucket>(makeGrainReference(sa)).Dispose())); }
/// <summary> /// An extension method to intercept the calls to DirectApplyIndexUpdate /// on an Index /// </summary> internal static Task <bool> ApplyIndexUpdate(this IndexInterface index, IIndexableGrain updatedGrain, Immutable <IMemberUpdate> update, bool isUniqueIndex, IndexMetaData idxMetaData, SiloAddress siloAddress = null) { if (index is ActiveHashIndexPartitionedPerSilo) { ActiveHashIndexPartitionedPerSiloBucket bucketInCurrentSilo = InsideRuntimeClient.Current.InternalGrainFactory.GetSystemTarget <ActiveHashIndexPartitionedPerSiloBucket>( GetAHashIndexPartitionedPerSiloGrainID(IndexUtils.GetIndexNameFromIndexGrain((IAddressable )index), index.GetType().GetGenericArguments()[1]), siloAddress ); return(bucketInCurrentSilo.DirectApplyIndexUpdate(updatedGrain, update, isUniqueIndex, idxMetaData /*, siloAddress*/)); } return(index.DirectApplyIndexUpdate(updatedGrain, update, isUniqueIndex, idxMetaData, siloAddress)); }
/// <summary> /// An extension method to intercept the calls to DirectApplyIndexUpdate on an Index, /// so that for a PerSilo index, it can obtain the GrainService of that index on the silo of the indexed grain. /// </summary> internal static Task <bool> ApplyIndexUpdate(this IIndexInterface index, SiloIndexManager siloIndexManager, IIndexableGrain updatedGrain, Immutable <IMemberUpdate> update, IndexMetaData idxMetaData, SiloAddress siloAddress = null) { if (index is IActiveHashIndexPartitionedPerSilo) { var bucketInCurrentSilo = siloIndexManager.GetGrainService <IActiveHashIndexPartitionedPerSiloBucket>( GetAHashIndexPartitionedPerSiloGrainReference(siloIndexManager, IndexUtils.GetIndexNameFromIndexGrain((IAddressable)index), index.GetType().GetGenericArguments()[1], siloAddress )); return(bucketInCurrentSilo.DirectApplyIndexUpdate(updatedGrain, update, idxMetaData.IsUniqueIndex, idxMetaData /*, siloAddress*/)); } return(index.DirectApplyIndexUpdate(updatedGrain, update, idxMetaData.IsUniqueIndex, idxMetaData, siloAddress)); }
private ISet <Task <IOrleansQueryResult <IIndexableGrain> > > GetResultQueries(Dictionary <SiloAddress, SiloStatus> hosts, object key) { ISet <Task <IOrleansQueryResult <IIndexableGrain> > > queriesToSilos = new HashSet <Task <IOrleansQueryResult <IIndexableGrain> > >(); int i = 0; var indexName = IndexUtils.GetIndexNameFromIndexGrain(this); foreach (SiloAddress siloAddress in hosts.Keys) { //query each silo queriesToSilos.Add(this.SiloIndexManager.GetGrainService <IActiveHashIndexPartitionedPerSiloBucket>( GetGrainReference(this.SiloIndexManager, indexName, siloAddress )).LookupAsync(/*result, */ key)); //TODO: a bug in OrleansStream currently prevents a GrainService from working with streams. ++i; } return(queriesToSilos); }
private ISet <Task <IOrleansQueryResult <IIndexableGrain> > > GetResultQueries(Dictionary <SiloAddress, SiloStatus> hosts, object key) { ISet <Task <IOrleansQueryResult <IIndexableGrain> > > queriesToSilos = new HashSet <Task <IOrleansQueryResult <IIndexableGrain> > >(); int i = 0; GrainId grainID = GetGrainID(IndexUtils.GetIndexNameFromIndexGrain(this)); foreach (SiloAddress siloAddress in hosts.Keys) { //query each silo queriesToSilos.Add(InsideRuntimeClient.Current.InternalGrainFactory.GetSystemTarget <ActiveHashIndexPartitionedPerSiloBucket>( grainID, siloAddress ).Lookup(/*result, */ key)); //TODO: because of a bug in OrleansStream, a SystemTarget cannot work with streams. It should be fixed later. ++i; } return(queriesToSilos); }
public async Task <V> LookupUnique(K key) { if (!(this.State.IndexStatus == IndexStatus.Available)) { throw LogException("Index is not still available", IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainBucket2); } if (this.State.IndexMap.TryGetValue(key, out HashIndexSingleBucketEntry <V> entry)) { return((entry.Values.Count == 1 && !entry.IsTentative) ? entry.Values.GetEnumerator().Current : throw LogException($"There are {entry.Values.Count} values for the unique lookup key \"{key}\" on index" + $" \"{IndexUtils.GetIndexNameFromIndexGrain(this)}\", and the entry is{(entry.IsTentative ? "" : " not")} tentative.", IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainBucket3)); } return((this.State.NextBucket != null) ? await((IHashIndexInterface <K, V>)GetNextBucket()).LookupUnique(key) : throw LogException($"The lookup key \"{key}\" does not exist on index \"{IndexUtils.GetIndexNameFromIndexGrain(this)}\".", IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainBucket4)); }
public async Task <V> LookupUnique(K key) { if (!(State.IndexStatus == IndexStatus.Available)) { var e = new Exception(string.Format("Index is not still available.")); GetLogger().Error((int)ErrorCode.IndexingIndexIsNotReadyYet_GrainBucket2, e.Message, e); throw e; } HashIndexSingleBucketEntry <V> entry; if (State.IndexMap.TryGetValue(key, out entry) && !entry.isTentative()) { if (entry.Values.Count() == 1) { return(entry.Values.GetEnumerator().Current); } else { var e = new Exception(string.Format("There are {0} values for the unique lookup key \"{1}\" does not exist on index \"{2}\".", entry.Values.Count(), key, IndexUtils.GetIndexNameFromIndexGrain(this))); GetLogger().Error((int)ErrorCode.IndexingIndexIsNotReadyYet_GrainBucket3, e.Message, e); throw e; } } else if (State.NextBucket != null) { return(await((HashIndexInterface <K, V>)GetNextBucket()).LookupUnique(key)); } else { var e = new Exception(string.Format("The lookup key \"{0}\" does not exist on index \"{1}\".", key, IndexUtils.GetIndexNameFromIndexGrain(this))); GetLogger().Error((int)ErrorCode.IndexingIndexIsNotReadyYet_GrainBucket4, e.Message, e); throw e; } }
public Task <V> LookupUniqueAsync(K key) { if (!(state.IndexStatus == IndexStatus.Available)) { throw LogException($"ParentIndex {_parentIndexName}: Index is not still available.", IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainServiceBucket3); } if (state.IndexMap.TryGetValue(key, out HashIndexSingleBucketEntry <V> entry) && !entry.IsTentative) { return((entry.Values.Count == 1) ? Task.FromResult(entry.Values.GetEnumerator().Current) : throw LogException($"ParentIndex {_parentIndexName}: There are {entry.Values.Count} values for the unique lookup key \"{key}\" on index \"{IndexUtils.GetIndexNameFromIndexGrain(this)}\".", IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainServiceBucket4)); } throw LogException($"ParentIndex {_parentIndexName}The lookup key \"{key}\" does not exist on index \"{IndexUtils.GetIndexNameFromIndexGrain(this)}\".", IndexingErrorCode.IndexingIndexIsNotReadyYet_GrainServiceBucket5); }
public Task <V> LookupUnique(K key) { if (!(State.IndexStatus == IndexStatus.Available)) { var e = new Exception(string.Format("Index is not still available.")); logger.Error((int)ErrorCode.IndexingIndexIsNotReadyYet_SystemTargetBucket3, e.Message, e); throw e; } HashIndexSingleBucketEntry <V> entry; if (State.IndexMap.TryGetValue(key, out entry) && !entry.isTentative()) { if (entry.Values.Count() == 1) { return(Task.FromResult(entry.Values.GetEnumerator().Current)); } else { var e = new Exception(string.Format("There are {0} values for the unique lookup key \"{1}\" does not exist on index \"{2}->{3}\".", entry.Values.Count(), key, _parentIndexName, IndexUtils.GetIndexNameFromIndexGrain(this))); logger.Error((int)ErrorCode.IndexingIndexIsNotReadyYet_SystemTargetBucket4, e.Message, e); throw e; } } else { var e = new Exception(string.Format("The lookup key \"{0}\" does not exist on index \"{1}->{2}\".", key, _parentIndexName, IndexUtils.GetIndexNameFromIndexGrain(this))); logger.Error((int)ErrorCode.IndexingIndexIsNotReadyYet_SystemTargetBucket5, e.Message, e); throw e; } }