Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public final void start() throws java.io.IOException
        public override void Start()
        {
            using (LockWrapper ignored = writeLock(_updateLock, _logger))
            {
                State = State.start(_stateInitializer);
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected final <Value> Value lookup(Key key, Reader<Value> reader) throws java.io.IOException
        protected internal Value Lookup <Value>(Key key, Reader <Value> reader)
        {
            ValueLookup <Value> lookup = new ValueLookup <Value>(reader);
            long retriesLeft           = MaxLookupRetryCount;

            while (retriesLeft > 0)
            {
                ProgressiveState <Key> originalState = this.State;
                try
                {
                    return(lookup.Value(!originalState.lookup(key, lookup)));
                }
                catch (FileIsNotMappedException e)
                {
                    // if the state has changed we think the exception is caused by a rotation event. In this
                    // case we simply retry the lookup on the rotated state. Otherwise we rethrow.
                    if (originalState == this.State)
                    {
                        throw e;
                    }
                }
                retriesLeft--;
            }
            throw new IOException(string.Format("Failed to lookup `{0}` in key value store, after {1:D} retries", key, MaxLookupRetryCount));
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public final void init() throws java.io.IOException
        public override void Init()
        {
            using (LockWrapper ignored = writeLock(_updateLock, _logger))
            {
                State = State.initialize(RotationStrategy);
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public final void shutdown() throws java.io.IOException
        public override void Shutdown()
        {
            using (LockWrapper ignored = writeLock(_updateLock, _logger))
            {
                _stopped = true;
                State    = State.stop();
            }
        }
Ejemplo n.º 5
0
 protected internal EntryUpdater <Key> Resetter(long version)
 {
     using (LockWrapper @lock = writeLock(_updateLock, _logger))
     {
         ProgressiveState <Key> current = State;
         return(current.Resetter(@lock.Get(), new RotationTask(this, version)));
     }
 }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private ProgressiveState<String> stateWithLookup(org.neo4j.function.ThrowingSupplier<bool, java.io.IOException> valueSupplier) throws java.io.IOException
        private ProgressiveState <string> StateWithLookup(ThrowingSupplier <bool, IOException> valueSupplier)
        {
            ProgressiveState <string> state = mock(typeof(ProgressiveState));

            when(state.lookup(any(), any())).thenAnswer(invocation =>
            {
                bool wasFound = valueSupplier.Get();
                invocation.getArgument <ValueLookup <string> >(1).value(null);
                return(wasFound);
            });
            return(state);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Prepare for rotation. Sets up the internal structures to ensure that all changes up to and including the changes
        /// of the specified version are applied before rotation takes place. This method does not block, however if all
        /// required changes have not been applied <seealso cref="PreparedRotation.rotate() the rotate method"/> will block
        /// waiting for all changes to be applied. Invoking <seealso cref="PreparedRotation.rotate() the rotate method"/> some
        /// time after all requested transactions have been applied is ok, since setting the store up for rotation does
        /// not block updates, it just sorts them into updates that apply before rotation and updates that apply after.
        /// </summary>
        /// <param name="version"> the smallest version to include in the rotation. Note that the actual rotated version might be a
        /// later version than this version. The actual rotated version is returned by
        /// <seealso cref="PreparedRotation.rotate()"/>. </param>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: protected final PreparedRotation prepareRotation(final long version)
        protected internal PreparedRotation PrepareRotation(long version)
        {
            using (LockWrapper ignored = writeLock(_updateLock, _logger))
            {
                ProgressiveState <Key> prior = State;
                if (prior.StoredVersion() == version && !prior.HasChanges())
                {
                    return(() => version);
                }
                return(new RotationTask(this, version));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Introspective feature, not thread safe. </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected final void visitAll(Visitor visitor) throws java.io.IOException
        protected internal void VisitAll(Visitor visitor)
        {
            ProgressiveState <Key> state = this.State;

            if (visitor is MetadataVisitor)
            {
                (( MetadataVisitor )visitor).VisitMetadata(state.File(), Headers(), state.storedEntryCount());
            }
            using (DataProvider provider = state.dataProvider())
            {
                Transfer(provider, visitor);
            }
        }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @Resources.Life(STARTED) public void accessClosedStateShouldThrow() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AccessClosedStateShouldThrow()
        {
            Store store = _resourceManager.managed(new Store(this));

            store.Put("test", "value");
            store.PrepareRotation(0).rotate();
            ProgressiveState <string> lookupState = store.State;

            store.PrepareRotation(0).rotate();

            _expectedException.expect(typeof(FileIsNotMappedException));
            _expectedException.expectMessage("File has been unmapped");

            lookupState.lookup("test", new ValueSinkAnonymousInnerClass(this));
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: public AbstractKeyValueStore(org.neo4j.io.fs.FileSystemAbstraction fs, org.neo4j.io.pagecache.PageCache pages, org.neo4j.io.layout.DatabaseLayout databaseLayout, RotationMonitor monitor, org.neo4j.logging.Logger logger, RotationTimerFactory timerFactory, org.neo4j.io.pagecache.tracing.cursor.context.VersionContextSupplier versionContextSupplier, int keySize, int valueSize, HeaderField<?>... headerFields)
        public AbstractKeyValueStore(FileSystemAbstraction fs, PageCache pages, DatabaseLayout databaseLayout, RotationMonitor monitor, Logger logger, RotationTimerFactory timerFactory, VersionContextSupplier versionContextSupplier, int keySize, int valueSize, params HeaderField <object>[] headerFields)
        {
            this._fs       = fs;
            this.KeySize   = keySize;
            this.ValueSize = valueSize;
            Rotation rotation = this.GetType().getAnnotation(typeof(Rotation));

            if (monitor == null)
            {
                monitor = RotationMonitor.NONE;
            }
            this._format               = new Format(this, headerFields);
            this._logger               = logger;
            this.RotationStrategy      = rotation.value().create(fs, pages, _format, monitor, databaseLayout);
            this._rotationTimerFactory = timerFactory;
            this.State = new DeadState.Stopped <Key>(_format, this.GetType().getAnnotation(typeof(State)).value(), versionContextSupplier);
        }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @Resources.Life(STARTED) @SuppressWarnings("unchecked") public void retryLookupOnConcurrentStoreStateChange() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RetryLookupOnConcurrentStoreStateChange()
        {
            Store store = _resourceManager.managed(new Store(this));

            ProgressiveState <string> workingState = StateWithLookup(() => true);
            ProgressiveState <string> staleState   = StateWithLookup(() =>
            {
                SetState(store, workingState);
                throw new FileIsNotMappedException(new File("/files/was/rotated/concurrently/during/lookup"));
            });

            SetState(store, staleState);

            assertEquals("New state contains stored value", "value", store.Lookup("test", StringReader("value")));

            // Should have 2 invocations: first throws exception, second re-read value.
            verify(staleState, times(1)).lookup(any(), any());
            verify(workingState, times(1)).lookup(any(), any());
        }
Ejemplo n.º 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long rotate(boolean force) throws java.io.IOException
            internal virtual long Rotate(bool force)
            {
                using (RotationState <Key> rotation = this.Rotation)
                {
                    try
                    {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long version = rotation.rotationVersion();
                        long version = rotation.RotationVersion();
                        ProgressiveState <Key> next = rotation.Rotate(force, outerInstance.RotationStrategy, outerInstance.rotationTimerFactory, value => updateHeaders(value, version));
                        using (LockWrapper ignored = writeLock(outerInstance.updateLock, outerInstance.logger))
                        {
                            outerInstance.State = next;
                        }
                        return(version);
                    }
                    catch (Exception t)
                    {
                        // Rotation failed. Here we assume that rotation state remembers this so that closing it
                        // won't close the state as it was before rotation began, which we're reverting to right here.
                        using (LockWrapper ignored = writeLock(outerInstance.updateLock, outerInstance.logger))
                        {
                            // Only mark as failed if we're still running.
                            // If shutdown has been called while being in rotation state then shutdown will fail
                            // without closing the store. This means that rotation takes over that responsibility.
                            // Therefore avoid marking rotation state as failed in this case and let the store
                            // be naturally closed before leaving this method.
                            if (!outerInstance.stopped)
                            {
                                outerInstance.State = rotation.MarkAsFailed();
                            }
                        }
                        throw t;
                    }
                }
            }
Ejemplo n.º 13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void setState(Store store, ProgressiveState<String> workingState) throws java.io.IOException
        private void SetState(Store store, ProgressiveState <string> workingState)
        {
            store.State.Dispose();
            store.State = workingState;
        }