private static async Task RemoveKeysWithPrefixAsync(
            ITransaction tx,
            IReliableDictionary2 <string, byte[]> relDict,
            string keyPrefix,
            CancellationToken cancellationToken)
        {
            var enumerable = await relDict.CreateKeyEnumerableAsync(tx, EnumerationMode.Ordered);

            var enumerator = enumerable.GetAsyncEnumerator();

            var canBreak = false;

            while (await enumerator.MoveNextAsync(cancellationToken))
            {
                if (enumerator.Current.StartsWith(keyPrefix, StringComparison.OrdinalIgnoreCase))
                {
                    canBreak = true;
                    await relDict.TryRemoveAsync(tx, enumerator.Current);
                }
                else
                {
                    if (canBreak)
                    {
                        break;
                    }
                }
            }
        }
        public async Task ClearAsync(ITransaction tx, string key)
        {
            var metadata = await GetMetadataAsync(tx, key).ConfigureAwait(false);

            var from  = metadata.From;
            var count = metadata.Count;

            for (var i = 0; i < count; i++)
            {
                var listKey = new ReliableListKey {
                    Key = key, Id = from + i
                };
                await _valueStore.TryRemoveAsync(tx, listKey).ConfigureAwait(false);
            }
            await UpdateMetadataAsync(tx, key, new ReliableListMetaData()).ConfigureAwait(false);
        }
Example #3
0
        private async Task RemoveAsync(ITransaction tx, TKey key, IEnumerable <string> words, TimeSpan timeout, CancellationToken token)
        {
            foreach (var word in words)
            {
                // This key should exist in the index for each word.
                var result = await _index.TryGetValueAsync(tx, word, LockMode.Update, timeout, token).ConfigureAwait(false);

                if (!result.HasValue)
                {
                    throw new KeyNotFoundException();
                }

                // Remove this key from the index.
                var updatedIndex = result.Value.CopyAndRemove(key);
                if (updatedIndex.Length > 0)
                {
                    // Update the index.
                    await _index.SetAsync(tx, word, updatedIndex, timeout, token).ConfigureAwait(false);
                }
                else
                {
                    // Remove the index completely if this was the last key with this filter value.
                    await _index.TryRemoveAsync(tx, word, timeout, token).ConfigureAwait(false);
                }
            }
        }
Example #4
0
        public async Task <ConditionalValue <TValue> > TryRemoveAsync(ITransaction tx, TKey key, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var result = await _dictionary.TryRemoveAsync(tx, key, timeout, cancellationToken).ConfigureAwait(false);

            if (result.HasValue)
            {
                await OnRemoveAsync(tx, key, result.Value, timeout, cancellationToken).ConfigureAwait(false);
            }

            return(result);
        }