Ejemplo n.º 1
0
 public IndexingExecuter(WorkContext context, Prefetcher prefetcher)
     : base(context)
 {
     autoTuner                  = new IndexBatchSizeAutoTuner(context);
     this.prefetcher            = prefetcher;
     defaultPrefetchingBehavior = prefetcher.CreatePrefetchingBehavior(PrefetchingUser.Indexer, autoTuner);
     prefetchingBehaviors.TryAdd(defaultPrefetchingBehavior);
 }
Ejemplo n.º 2
0
 public IndexingExecuter(WorkContext context, Prefetcher prefetcher, IndexReplacer indexReplacer)
     : base(context, indexReplacer)
 {
     autoTuner                  = new IndexBatchSizeAutoTuner(context);
     this.prefetcher            = prefetcher;
     defaultPrefetchingBehavior = prefetcher.CreatePrefetchingBehavior(PrefetchingUser.Indexer, autoTuner);
     defaultPrefetchingBehavior.ShouldHandleUnusedDocumentsAddedAfterCommit = true;
     prefetchingBehaviors.TryAdd(defaultPrefetchingBehavior);
 }
Ejemplo n.º 3
0
        // This method will automatically be called repeatedly until no conflict remains.
        private static void ConflictResolvingLoop(iOSGKSavedGame[] conflictingGames, bool prefetchData,
                                                  iOSConflictCallback conflictCallback,
                                                  Action <iOSGKSavedGame, string> completedCallback)
        {
            if (conflictingGames.Length == 1)
            {
                // No more conflict!
                var openedSavedGame = conflictingGames[0];
                completedCallback(openedSavedGame, null);
                return;
            }

            // The 1st element in the array is always the base game.
            // Either it is the game with oldest timestamp to start with,
            // or the resolved game of the previous conflict resolution request.
            var baseGame   = conflictingGames[0];
            var remoteGame = conflictingGames[1];

            var resolver = new NativeConflictResolver(
                baseGame,
                remoteGame,
                completedCallback,
                updatedConflictingGames =>
                ConflictResolvingLoop(updatedConflictingGames, prefetchData, conflictCallback, completedCallback)
                );

            // Invoke the conflict callback immediately if we don't need to prefetch data
            if (!prefetchData)
            {
                conflictCallback(resolver, baseGame, null, remoteGame, null);
                return;
            }

            // If we have to prefetch the data, we delegate invoking the conflict resolution
            // callback to the joiner instance (once both callbacks resolve, the joiner will
            // invoke the lambda that we declare here, using the fetched data).
            Prefetcher joiner = new Prefetcher((baseData, remoteData) =>
                                               conflictCallback(resolver, baseGame, baseData, remoteGame, remoteData),
                                               completedCallback);

            // Kick off the read calls.
            InternalLoadSavedGameData(baseGame, joiner.OnBaseDataRead);
            InternalLoadSavedGameData(remoteGame, joiner.OnRemoteDataRead);
        }
Ejemplo n.º 4
0
 private void InternalManualOpen(string filename, DataSource source, bool prefetchDataOnConflict, ConflictCallback conflictCallback, Action <SavedGameRequestStatus, ISavedGameMetadata> completedCallback)
 {
     mSnapshotManager.Open(filename, AsDataSource(source), Types.SnapshotConflictPolicy.MANUAL, delegate(GooglePlayGames.Native.PInvoke.SnapshotManager.OpenResponse response)
     {
         if (!response.RequestSucceeded())
         {
             completedCallback(AsRequestStatus(response.ResponseStatus()), null);
         }
         else if (response.ResponseStatus() == CommonErrorStatus.SnapshotOpenStatus.VALID)
         {
             completedCallback(SavedGameRequestStatus.Success, response.Data());
         }
         else if (response.ResponseStatus() == CommonErrorStatus.SnapshotOpenStatus.VALID_WITH_CONFLICT)
         {
             NativeSnapshotMetadata original = response.ConflictOriginal();
             NativeSnapshotMetadata unmerged = response.ConflictUnmerged();
             NativeConflictResolver resolver = new NativeConflictResolver(mSnapshotManager, response.ConflictId(), original, unmerged, completedCallback, delegate
             {
                 InternalManualOpen(filename, source, prefetchDataOnConflict, conflictCallback, completedCallback);
             });
             if (!prefetchDataOnConflict)
             {
                 conflictCallback(resolver, original, null, unmerged, null);
             }
             else
             {
                 Prefetcher @object = new Prefetcher(delegate(byte[] originalData, byte[] unmergedData)
                 {
                     conflictCallback(resolver, original, originalData, unmerged, unmergedData);
                 }, completedCallback);
                 mSnapshotManager.Read(original, @object.OnOriginalDataRead);
                 mSnapshotManager.Read(unmerged, @object.OnUnmergedDataRead);
             }
         }
         else
         {
             Logger.e("Unhandled response status");
             completedCallback(SavedGameRequestStatus.InternalError, null);
         }
     });
 }
Ejemplo n.º 5
0
        public RavenConfiguration Initialize()
        {
            Core.Initialize(Settings);
            Replication.Initialize(Settings);
            Queries.Initialize(Settings);
            Patching.Initialize(Settings);
            BulkInsert.Initialize(Settings);
            Server.Initialize(Settings);
            Memory.Initialize(Settings);
            Indexing.Initialize(Settings);
            Prefetcher.Initialize(Settings);
            Storage.Initialize(Settings);
            Encryption.Initialize(Settings);
            Cluster.Initialize(Settings);
            Monitoring.Initialize(Settings);
            FileSystem.Initialize(Settings);
            Counter.Initialize(Settings);
            TimeSeries.Initialize(Settings);
            Expiration.Initialize(Settings);
            Versioning.Initialize(Settings);
            Studio.Initialize(Settings);
            Tenants.Initialize(Settings);
            Licensing.Initialize(Settings);
            Quotas.Initialize(Settings);

            if (Settings["Raven/MaxServicePointIdleTime"] != null)
            {
                ServicePointManager.MaxServicePointIdleTime = Convert.ToInt32(Settings["Raven/MaxServicePointIdleTime"]);
            }

            if (ConcurrentMultiGetRequests == null)
            {
                ConcurrentMultiGetRequests = new SemaphoreSlim(Server.MaxConcurrentMultiGetRequests);
            }

            PostInit();

            initialized = true;

            return(this);
        }
Ejemplo n.º 6
0
 public IndexingExecuter(WorkContext context, DatabaseEtagSynchronizer synchronizer, Prefetcher prefetcher)
     : base(context)
 {
     autoTuner           = new IndexBatchSizeAutoTuner(context);
     etagSynchronizer    = synchronizer.GetSynchronizer(EtagSynchronizerType.Indexer);
     prefetchingBehavior = prefetcher.GetPrefetchingBehavior(PrefetchingUser.Indexer);
 }
Ejemplo n.º 7
0
        public DocumentDatabase(InMemoryRavenConfiguration configuration, TransportState transportState = null)
        {
            DocumentLock        = new PutSerialLock();
            Name                = configuration.DatabaseName;
            Configuration       = configuration;
            this.transportState = transportState ?? new TransportState();
            ExtensionsState     = new AtomicDictionary <object>();

            using (LogManager.OpenMappedContext("database", Name ?? Constants.SystemDatabase))
            {
                Log.Debug("Start loading the following database: {0}", Name ?? Constants.SystemDatabase);

                initializer = new DocumentDatabaseInitializer(this, configuration);

                initializer.InitializeEncryption();
                initializer.ValidateLicense();

                initializer.SubscribeToDomainUnloadOrProcessExit();
                initializer.ExecuteAlterConfiguration();
                initializer.SatisfyImportsOnce();

                backgroundTaskScheduler = configuration.CustomTaskScheduler ?? TaskScheduler.Default;


                recentTouches = new SizeLimitedConcurrentDictionary <string, TouchedDocumentInfo>(configuration.MaxRecentTouchesToRemember, StringComparer.OrdinalIgnoreCase);

                configuration.Container.SatisfyImportsOnce(this);

                workContext = new WorkContext
                {
                    Database            = this,
                    DatabaseName        = Name,
                    IndexUpdateTriggers = IndexUpdateTriggers,
                    ReadTriggers        = ReadTriggers,
                    TaskScheduler       = backgroundTaskScheduler,
                    Configuration       = configuration,
                    IndexReaderWarmers  = IndexReaderWarmers
                };

                try
                {
                    uuidGenerator = new SequentialUuidGenerator();
                    initializer.InitializeTransactionalStorage(uuidGenerator);
                    lastCollectionEtags = new LastCollectionEtags(TransactionalStorage, WorkContext);
                }
                catch (Exception)
                {
                    if (TransactionalStorage != null)
                    {
                        TransactionalStorage.Dispose();
                    }
                    throw;
                }

                try
                {
                    TransactionalStorage.Batch(actions => uuidGenerator.EtagBase = actions.General.GetNextIdentityValue("Raven/Etag"));

                    // Index codecs must be initialized before we try to read an index
                    InitializeIndexCodecTriggers();
                    initializer.InitializeIndexStorage();

                    Attachments   = new AttachmentActions(this, recentTouches, uuidGenerator, Log);
                    Documents     = new DocumentActions(this, recentTouches, uuidGenerator, Log);
                    Indexes       = new IndexActions(this, recentTouches, uuidGenerator, Log);
                    Maintenance   = new MaintenanceActions(this, recentTouches, uuidGenerator, Log);
                    Notifications = new NotificationActions(this, recentTouches, uuidGenerator, Log);
                    Patches       = new PatchActions(this, recentTouches, uuidGenerator, Log);
                    Queries       = new QueryActions(this, recentTouches, uuidGenerator, Log);
                    Tasks         = new TaskActions(this, recentTouches, uuidGenerator, Log);
                    Transformers  = new TransformerActions(this, recentTouches, uuidGenerator, Log);

                    inFlightTransactionalState = TransactionalStorage.GetInFlightTransactionalState(Documents.Put, Documents.Delete);

                    CompleteWorkContextSetup();

                    prefetcher       = new Prefetcher(workContext);
                    indexingExecuter = new IndexingExecuter(workContext, prefetcher);

                    RaiseIndexingWiringComplete();

                    InitializeTriggersExceptIndexCodecs();
                    SecondStageInitialization();
                    ExecuteStartupTasks();
                    lastCollectionEtags.Initialize();

                    Log.Debug("Finish loading the following database: {0}", configuration.DatabaseName ?? Constants.SystemDatabase);
                }
                catch (Exception)
                {
                    Dispose();
                    throw;
                }
            }
        }
Ejemplo n.º 8
0
 public IndexingExecuter(WorkContext context, Prefetcher prefetcher)
     : base(context)
 {
     autoTuner           = new IndexBatchSizeAutoTuner(context);
     prefetchingBehavior = prefetcher.GetPrefetchingBehavior(PrefetchingUser.Indexer, autoTuner);
 }
        private void InternalOpen(string filename, DataSource source, ConflictResolutionStrategy resolutionStrategy,
                                  bool prefetchDataOnConflict, ConflictCallback conflictCallback,
                                  Action <SavedGameRequestStatus, ISavedGameMetadata> completedCallback)
        {
            Types.SnapshotConflictPolicy policy;
            switch (resolutionStrategy)
            {
            case ConflictResolutionStrategy.UseLastKnownGood:
                policy = Types.SnapshotConflictPolicy.LAST_KNOWN_GOOD;
                break;

            case ConflictResolutionStrategy.UseMostRecentlySaved:
                policy = Types.SnapshotConflictPolicy.MOST_RECENTLY_MODIFIED;
                break;

            case ConflictResolutionStrategy.UseLongestPlaytime:
                policy = Types.SnapshotConflictPolicy.LONGEST_PLAYTIME;
                break;

            case ConflictResolutionStrategy.UseManual:
                policy = Types.SnapshotConflictPolicy.MANUAL;
                break;

            default:
                policy = Types.SnapshotConflictPolicy.MOST_RECENTLY_MODIFIED;
                break;
            }

            mSnapshotManager.Open(filename, AsDataSource(source), policy,
                                  response =>
            {
                if (!response.RequestSucceeded())
                {
                    completedCallback(AsRequestStatus(response.ResponseStatus()), null);
                }
                else if (response.ResponseStatus() == Status.SnapshotOpenStatus.VALID)
                {
                    completedCallback(SavedGameRequestStatus.Success, response.Data());
                }
                else if (response.ResponseStatus() ==
                         Status.SnapshotOpenStatus.VALID_WITH_CONFLICT)
                {
                    // If we get here, manual conflict resolution is required.
                    NativeSnapshotMetadata original = response.ConflictOriginal();
                    NativeSnapshotMetadata unmerged = response.ConflictUnmerged();

                    // Instantiate the conflict resolver. Note that the retry callback closes over
                    // all the parameters we need to retry the open attempt. Once the conflict is
                    // resolved by invoking the appropriate resolution method on
                    // NativeConflictResolver, the resolver will invoke this callback, which will
                    // result in this method being re-executed. This recursion will continue until
                    // all conflicts are resolved or an error occurs.
                    NativeConflictResolver resolver = new NativeConflictResolver(
                        mSnapshotManager,
                        response.ConflictId(),
                        original,
                        unmerged,
                        completedCallback,
                        () => InternalOpen(filename, source, resolutionStrategy,
                                           prefetchDataOnConflict,
                                           conflictCallback, completedCallback)
                        );

                    // If we don't have to pre-fetch the saved games' binary data, we can
                    // immediately invoke the conflict callback. Note that this callback is
                    // constructed to execute on the game thread in
                    // OpenWithManualConflictResolution.
                    if (!prefetchDataOnConflict)
                    {
                        conflictCallback(resolver, original, null, unmerged, null);
                        return;
                    }

                    // If we have to prefetch the data, we delegate invoking the conflict resolution
                    // callback to the joiner instance (once both callbacks resolve, the joiner will
                    // invoke the lambda that we declare here, using the fetched data).
                    Prefetcher joiner = new Prefetcher((originalData, unmergedData) =>
                                                       conflictCallback(resolver, original, originalData, unmerged, unmergedData),
                                                       completedCallback);

                    // Kick off the read calls.
                    mSnapshotManager.Read(original, joiner.OnOriginalDataRead);
                    mSnapshotManager.Read(unmerged, joiner.OnUnmergedDataRead);
                }
                else
                {
                    Logger.e("Unhandled response status");
                    completedCallback(SavedGameRequestStatus.InternalError, null);
                }
            });
        }
Ejemplo n.º 10
0
 private void Prefetch(int i)
 {
     Item item = changesets[i].Changes[0].Item;
     filenames[i] = Path.GetTempFileName();
     manualResetEvents[i] = new ManualResetEvent(false);
     Prefetcher prefetcher = new Prefetcher(item, filenames[i], manualResetEvents[i]);
     ThreadPool.QueueUserWorkItem(prefetcher.Prefetch);
 }