Esempio n. 1
0
        /// <summary>
        /// Switch Modes.
        /// </summary>
        /// <remarks>
        /// Reader works in 2 modes. Cached, or direct. This routine allows us to switch between these 2 modes.
        /// Switch is expected to happen when a replica become primary (switch to cached) and when it loses primary status.
        /// </remarks>
        /// <param name="newMode"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task SwitchModeAsync(DataReaderMode newMode, CancellationToken token)
        {
            if (newMode == this.dataReaderMode)
            {
                EventStoreLogger.Logger.LogMessage("Target Mode: {0} == Current Mode. No-Op", this.dataReaderMode);
                return;
            }

            EventStoreLogger.Logger.LogMessage("Current Mode: {0}, New Mode: {1}", this.dataReaderMode, newMode);

            // We do the switch under lock.
            await this.singleAccess.WaitAsync(token).ConfigureAwait(false);

            try
            {
                if (this.azureAccessObject != null)
                {
                    EventStoreLogger.Logger.LogMessage("Releasing Azure Access Object");
                    await this.azureAccessObject.ReleaseAccessAsync(token).ConfigureAwait(false);

                    this.azureAccessObject = null;
                }

                this.dataReaderMode = newMode;
                this.initialized    = false;
            }
            finally
            {
                this.singleAccess.Release();
            }

            await this.InitIfRequiredAsync(token).ConfigureAwait(false);
        }
Esempio n. 2
0
 public ServiceFabricAzureTableRecordSession(string accountName, string accountKey, bool useHttps, string tableNamePrefix, string deploymentId)
 {
     Assert.IsNotNull(accountName, "accountName != null");
     Assert.IsNotNull(accountKey, "accountKey != null");
     this.tableAccess   = new AccountAndKeyTableStorageAccess(accountName, accountKey, useHttps);
     this.dataDecorator = new ServiceFabricAzureAccessDataDecorator(this.tableAccess, tableNamePrefix, deploymentId);
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceFabricAzureTableAccess" /> class.
        /// </summary>
        /// <param name="storageTableAccessor">Information used to connect to Azure storage account.</param>
        /// <param name="namePrefix">The prefix of table names.</param>
        /// <param name="deploymentId"></param>
        public ServiceFabricAzureAccessDataDecorator(IAzureTableStorageAccess tableAccess, string namePrefix, string deploymentId)
        {
            if (tableAccess == null)
            {
                throw new ArgumentNullException("tableAccess");
            }

            this.strorageTableAccess      = tableAccess;
            this.tableNamePrefix          = string.IsNullOrEmpty(namePrefix) ? DefaultTableNamePrefix : namePrefix;;
            this.userSuppliedDeploymentId = deploymentId;
        }
Esempio n. 4
0
 public DataFetcher(string tableName, string namePrefix, string deploymentId, int maxSingleTakeCount, IAzureTableStorageAccess azureTableAccess)
 {
     Assert.IsNotEmptyOrNull(tableName, "tableName != null");
     Assert.IsNotNull(azureTableAccess, "azureTableAccess != null");
     this.tableName          = tableName;
     this.filterBuilder      = new AzureTimeLoggedBasedFilterBuilder();
     this.azureTableAccess   = azureTableAccess;
     this.namePrefix         = namePrefix;
     this.deploymentId       = deploymentId;
     this.decoratedTableName = null;
     this.takeCount          = maxSingleTakeCount;
 }
Esempio n. 5
0
        public AzureTableStoreStorageAccessInformation(
            IAzureTableStorageAccess azureTableAccess,
            string tableNamePrefix,
            string deploymentId)
        {
            Assert.IsNotNull(azureTableAccess, "azureTableAccess != null");
            Assert.IsNotEmptyOrNull(tableNamePrefix, "tableNamePrefix != null/empty");

            this.AzureTableStorageAccess = azureTableAccess;
            this.TableNamePrefix         = tableNamePrefix;
            this.DeploymentId            = deploymentId;
        }
        public static async Task <IEnumerable <AzureTablePropertyBag> > ExecuteQueryWithFilterAsync(
            IAzureTableStorageAccess tableAccess,
            string tableName,
            IEnumerable <TraceRecord> recordsInterestedIn,
            IEnumerable <TraceRecordFilter> recordFilters,
            DateTimeOffset startTime,
            DateTimeOffset endTime,
            CancellationToken token)
        {
            var  serverSideQueryFilter  = string.Empty;
            bool serverSideQueryCreated = TryCreateQueryFilterForTable(tableName, recordsInterestedIn, recordFilters, out serverSideQueryFilter);

            if (!serverSideQueryCreated)
            {
                serverSideQueryFilter = string.Empty;
            }

            Func <AzureTablePropertyBag, bool> clientSideFilteringFunction = (oneResult) => IsMatch(oneResult, recordFilters);

            var queryResult = await tableAccess.ExecuteQueryAsync(
                tableName,
                new AzureTimeLoggedBasedFilterBuilder(),
                serverSideQueryFilter,
                clientSideFilteringFunction,
                startTime,
                endTime,
                MaxNumberOfRecordsToQuery,
                token).ConfigureAwait(false);

            var returnResult = queryResult.AzureTableProperties.OrderByDescending(item => item.TimeLogged).ToList();

            if (returnResult.Count() > MaxNumberOfRecordsToReturn)
            {
                returnResult = returnResult.Take(MaxNumberOfRecordsToReturn).ToList();
            }

            return(returnResult);
        }
Esempio n. 7
0
        private async Task InitIfRequiredAsync(CancellationToken token)
        {
            if (this.initialized)
            {
                return;
            }

            await this.singleAccess.WaitAsync(token).ConfigureAwait(false);

            if (this.initialized)
            {
                return;
            }

            EventStoreLogger.Logger.LogMessage("Doing Reader Initialization");

            try
            {
                TraceStoreConnectionInformation connectionInfo = null;

                if (ClusterSettingsReader.IsOneBoxEnvironment())
                {
                    EventStoreLogger.Logger.LogMessage("One Box Environment. Configuring local Reader");
                    connectionInfo = new LocalTraceStoreConnectionInformation(
                        FabricEnvironment.GetDataRoot(),
                        FabricEnvironment.GetLogRoot(),
                        FabricEnvironment.GetCodePath());
                }
                else
                {
                    EventStoreLogger.Logger.LogMessage("Cloud Environment. Configuring Cloud Reader. Mode : {0}", this.dataReaderMode);
                    var operationalConsumer = ClusterSettingsReader.OperationalConsumer;
                    if (operationalConsumer == null)
                    {
                        throw new ConnectionParsingException(ErrorCodes.AzureConnectionInformationMissing, "Config is Missing Operational Store Connection information");
                    }

                    if (this.dataReaderMode == DataReaderMode.CacheMode)
                    {
                        EventStoreLogger.Logger.LogMessage("Caching is Enabled.");

                        this.azureAccessObject = new AzureTableCachedStorageAccess(
                            new CachePolicy(MaxDaysToMaintainCache, MaxItemsToCache, TimeSpan.FromHours(8)),
                            operationalConsumer.Connection.AccountName,
                            HandyUtil.ConvertToUnsecureString(operationalConsumer.Connection.AccountKey),
                            true,
                            operationalConsumer.TablesPrefix,
                            operationalConsumer.DeploymentId);

                        // Kick-off the Cache Update Task. This task is launched in a separate Task
                        // which is monitored by the TaskRunner and therefore doesn't need to be monitored here.
                        var task = ((AzureTableCachedStorageAccess)azureAccessObject).KickOffUpdaterAsync(token);
                    }
                    else
                    {
                        EventStoreLogger.Logger.LogMessage("Caching is Disabled");

                        this.azureAccessObject = new AccountAndKeyTableStorageAccess(
                            operationalConsumer.Connection.AccountName,
                            HandyUtil.ConvertToUnsecureString(operationalConsumer.Connection.AccountKey),
                            true);
                    }

                    connectionInfo = new AzureTableStoreStorageAccessInformation(azureAccessObject, operationalConsumer.TablesPrefix, operationalConsumer.DeploymentId);
                }

                var connection = new TraceStoreConnection(connectionInfo, EventStoreLogProvider.LogProvider);
                traceStoreReader = connection.EventStoreReader;
                this.initialized = true;
            }
            finally
            {
                this.singleAccess.Release();
            }
        }
        public AzureTableCachedStorageAccess(CachePolicy policy, string name, string key, bool useHttps, string tableNamePrefix, string deploymentId)
        {
            Assert.IsNotNull(policy, "policy");

            this.logger = EventStoreLogger.Logger;

            this.cachingPolicy = policy;

            this.tableExistsMap = new Dictionary <string, bool>();

            this.LastCacheTelemetryDump = DateTimeOffset.UtcNow;

            this.cancellationTokenSourceForBackgroundUpdater = null;

            this.azureTableDirectAccess = new AccountAndKeyTableStorageAccess(name, key, useHttps);

            this.nodeCache = new Cache <AzureTableCacheKey, AzureTableCacheValue>(
                "NodeCache",
                new InMemorySortedStore <AzureTableCacheKey, AzureTableCacheValue>(),
                new DataFetcher <AzureTableCacheKey, AzureTableCacheValue>(Mapping.NodeTable, tableNamePrefix, deploymentId, this.cachingPolicy.MaxCacheItemCount, this.azureTableDirectAccess),
                this.cachingPolicy);

            this.partitionCache = new Cache <AzureTableCacheKey, AzureTableCacheValue>(
                "PartitionCache",
                new InMemorySortedStore <AzureTableCacheKey, AzureTableCacheValue>(),
                new DataFetcher <AzureTableCacheKey, AzureTableCacheValue>(Mapping.PartitionTable, tableNamePrefix, deploymentId, this.cachingPolicy.MaxCacheItemCount, this.azureTableDirectAccess),
                this.cachingPolicy);

            this.applicationCache = new Cache <AzureTableCacheKey, AzureTableCacheValue>(
                "ApplicationCache",
                new InMemorySortedStore <AzureTableCacheKey, AzureTableCacheValue>(),
                new DataFetcher <AzureTableCacheKey, AzureTableCacheValue>(Mapping.AppTable, tableNamePrefix, deploymentId, this.cachingPolicy.MaxCacheItemCount, this.azureTableDirectAccess),
                this.cachingPolicy);

            this.serviceCache = new Cache <AzureTableCacheKey, AzureTableCacheValue>(
                "ServiceCache",
                new InMemorySortedStore <AzureTableCacheKey, AzureTableCacheValue>(),
                new DataFetcher <AzureTableCacheKey, AzureTableCacheValue>(Mapping.ServiceTable, tableNamePrefix, deploymentId, this.cachingPolicy.MaxCacheItemCount, this.azureTableDirectAccess),
                this.cachingPolicy);

            this.replicaCache = new Cache <AzureTableCacheKey, AzureTableCacheValue>(
                "ReplicaCache",
                new InMemorySortedStore <AzureTableCacheKey, AzureTableCacheValue>(),
                new DataFetcher <AzureTableCacheKey, AzureTableCacheValue>(Mapping.ReplicaTable, tableNamePrefix, deploymentId, this.cachingPolicy.MaxCacheItemCount, this.azureTableDirectAccess),
                this.cachingPolicy);

            this.clusterCache = new Cache <AzureTableCacheKey, AzureTableCacheValue>(
                "ClusterCache",
                new InMemorySortedStore <AzureTableCacheKey, AzureTableCacheValue>(),
                new DataFetcher <AzureTableCacheKey, AzureTableCacheValue>(Mapping.ClusterTable, tableNamePrefix, deploymentId, this.cachingPolicy.MaxCacheItemCount, this.azureTableDirectAccess),
                this.cachingPolicy);

            this.correlationCache = new Cache <AzureTableCacheKey, AzureTableCacheValue>(
                "CorrelationCache",
                new InMemorySortedStore <AzureTableCacheKey, AzureTableCacheValue>(),
                new DataFetcher <AzureTableCacheKey, AzureTableCacheValue>(Mapping.CorrelationTable, tableNamePrefix, deploymentId, this.cachingPolicy.MaxCacheItemCount, this.azureTableDirectAccess),
                this.cachingPolicy);

            this.cacheList = new List <Cache <AzureTableCacheKey, AzureTableCacheValue> >();
            this.cacheList.Add(this.nodeCache);
            this.cacheList.Add(this.partitionCache);
            this.cacheList.Add(this.applicationCache);
            this.cacheList.Add(this.serviceCache);
            this.cacheList.Add(this.replicaCache);
            this.cacheList.Add(this.clusterCache);
            this.cacheList.Add(this.correlationCache);
        }
Esempio n. 9
0
 public ServiceFabricAzureTableRecordSession(IAzureTableStorageAccess access, string tableNamePrefix, string deploymentId)
 {
     Assert.IsNotNull(access, "access != null");
     this.tableAccess   = access;
     this.dataDecorator = new ServiceFabricAzureAccessDataDecorator(this.tableAccess, tableNamePrefix, deploymentId);
 }