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);
        }
        async Task IndexInterface.Lookup(IOrleansQueryResultStream <IIndexableGrain> result, object key)
        {
            if (logger.IsVerbose)
            {
                logger.Verbose("Streamed index lookup called for key = {0}", key);
            }

            //get all silos
            Dictionary <SiloAddress, SiloStatus> hosts = await SiloUtils.GetHosts(true);

            ISet <Task <IOrleansQueryResult <IIndexableGrain> > > queriesToSilos = GetResultQueries(hosts, key);

            //TODO: After fixing the problem with OrleansStream, this part is not needed anymore
            while (queriesToSilos.Count > 0)
            {
                // Identify the first task that completes.
                Task <IOrleansQueryResult <IIndexableGrain> > firstFinishedTask = await Task.WhenAny(queriesToSilos);

                // ***Remove the selected task from the list so that you don't
                // process it more than once.
                queriesToSilos.Remove(firstFinishedTask);

                // Await the completed task.
                IOrleansQueryResult <IIndexableGrain> partialResult = await firstFinishedTask;

                await result.OnNextBatchAsync(partialResult);
            }
            await result.OnCompletedAsync();
        }
Beispiel #3
0
        private static async Task <IEnumerable <Tuple <GrainId, string, int> > > GetGrainActivations()
        {
            Dictionary <SiloAddress, SiloStatus> hosts = await SiloUtils.GetHosts(true);

            SiloAddress[] silos = hosts.Keys.ToArray();
            return(await GetGrainActivations(silos));
        }
        private async Task <IEnumerable <Tuple <GrainId, string, int> > > GetGrainActivations(SiloAddress[] hostsIds)
        {
            IEnumerable <Task <List <Tuple <GrainId, string, int> > > > all = SiloUtils.GetSiloAddresses(hostsIds).Select(s => SiloUtils.GetSiloControlReference(s).GetGrainStatistics());

            List <Tuple <GrainId, string, int> >[] result = await Task.WhenAll(all);

            return(result.SelectMany(s => s));
        }
        async Task <IOrleansQueryResult <IIndexableGrain> > IndexInterface.Lookup(object key)
        {
            if (logger.IsVerbose)
            {
                logger.Verbose("Eager index lookup called for key = {0}", key);
            }

            //get all silos
            Dictionary <SiloAddress, SiloStatus> hosts = await SiloUtils.GetHosts(true);

            IEnumerable <IIndexableGrain>[] queriesToSilos = await Task.WhenAll(GetResultQueries(hosts, key));

            return(new OrleansQueryResult <V>(queriesToSilos.SelectMany(res => res.Select(e => e.AsReference <V>())).ToList()));
        }
 private Task <Dictionary <SiloAddress, SiloStatus> > GetHosts(bool onlyActive = false)
 {
     return(SiloUtils.GetHosts(onlyActive));
 }