コード例 #1
0
    @SuppressWarnings("unchecked")
    @Override
    protected void getAsync(UserTObject object, Object key, FutureWithCallback<Object> future) {
        if (object.getSharedVersion_objectfabric().getUnion() instanceof Record) {
            long record = getOrFetchRecord(object.getSharedVersion_objectfabric());

            if (Record.isStored(record)) {
                BTree tree = BTree.load(getRecordManager(), record, false);
                _writer.write(key);
                byte[] data = new byte[_writer.getOffset()];
                PlatformAdapter.arraycopy(_writer.getBuffer(), 0, data, 0, data.length);
                long id = tree.fetch(data);

                if (id != 0) {
                    data = getRecordManager().fetch(id);
                    Object value = _reader.read(data);

                    _reader.readVersions();

                    Version version = _reader.getOrCreateVersion(object);
                    TKeyedEntry entry = new TKeyedEntry(key, TKeyed.hash(key), value, false);

                    if (Debug.ENABLED)
                        Debug.assertion(value != TKeyedEntry.REMOVAL);

                    ((LazyMapVersion) version).putEntry(key, entry, true, true);
                    _reader.importVersions();
                    future.set(value);
                    return;
                }
            }
        }

        future.set(null);
    }
コード例 #2
0
    @Override
    protected void onVisitingVersions(Visitor visitor, Version shared) {
        super.onVisitingVersions(visitor, shared);

        if (Debug.ENABLED)
            Debug.assertion(_writer.getLimit() == _writer.getBuffer().length);

        _writer.reset();
    }
コード例 #3
0
ファイル: StoreCopyServer.java プロジェクト: lassewesth/neo4j
  /** @return a {@link RequestContext} specifying at which point the store copy started. */
  public RequestContext flushStoresAndStreamStoreFiles(StoreWriter writer, boolean includeLogs) {
    try {
      long lastAppliedTransaction = transactionIdStore.getLastClosedTransactionId();
      monitor.startFlushingEverything();
      logRotationControl.forceEverything();
      monitor.finishFlushingEverything();
      ByteBuffer temporaryBuffer = ByteBuffer.allocateDirect(1024 * 1024);

      // Copy the store files
      monitor.startStreamingStoreFiles();
      try (ResourceIterator<File> files = dataSource.listStoreFiles(includeLogs)) {
        while (files.hasNext()) {
          File file = files.next();
          try (StoreChannel fileChannel = fileSystem.open(file, "r")) {
            monitor.startStreamingStoreFile(file);
            writer.write(
                relativePath(storeDirectory, file),
                fileChannel,
                temporaryBuffer,
                file.length() > 0);
            monitor.finishStreamingStoreFile(file);
          }
        }
      } finally {
        monitor.finishStreamingStoreFiles();
      }

      return anonymous(lastAppliedTransaction);
    } catch (IOException e) {
      throw new ServerFailureException(e);
    }
  }
コード例 #4
0
    @Override
    protected Action onVisitingTObject(Visitor visitor, TObject object) {
        Action action = super.onVisitingTObject(visitor, object);

        if (action == Action.VISIT) {
            /*
             * TODO write version to a cache, for now writer will snapshot entire object
             * for each change.
             */

            // Object union = ((Version) object).getUnion();
            //
            // if (!(union instanceof Record))
            // return Action.SKIP;
            //
            // if (((Record) union).getRecord() == Record.NULL)
            // return Action.SKIP;

            Version shared = (Version) object;
            long record = getOrFetchRecord(shared);
            int id = shared.getClassId();

            if (record != Record.NOT_STORED) {
                // TODO: temporary: other objects should not be snapshotted
                if (id == DefaultObjectModel.COM_OBJECTFABRIC_TMAP_CLASS_ID || id == DefaultObjectModel.COM_OBJECTFABRIC_TSET_CLASS_ID)
                    return Action.VISIT;

                _writer.snapshot(shared);
            } else {
                /*
                 * Lazy objects must always be stored, otherwise during construction their
                 * content can get GCed before the lazy object is added to the store.
                 */
                if (id == DefaultObjectModelBase.COM_OBJECTFABRIC_LAZYMAP_CLASS_ID)
                    return Action.VISIT;
            }
        }

        return Action.SKIP;
    }
コード例 #5
0
    public final void start() {
        onStarting();

        long sessionsId = _jdbm.getRoot(SESSIONS);

        if (sessionsId != 0) {
            _sessions = BTree.load(_jdbm, sessionsId, true);

            if (_sessions == null)
                throw new RuntimeIOException(Strings.CORRUPTED_STORE);
        } else {
            _sessions = new BTree(_jdbm, true);
            _jdbm.setRoot(SESSIONS, _sessions.getId());
        }

        if (Debug.THREADS) {
            ThreadAssert.exchangeGive(this, _sessions);
            ThreadAssert.exchangeGiveList(this, _reader.getThreadContextObjects());
            ThreadAssert.exchangeGiveList(this, _writer.getThreadContextObjects());
            ThreadAssert.exchangeGive(this, this);
        }

        onStarted();
    }
コード例 #6
0
    @Override
    protected void onVisitedVersions(Visitor visitor, Version shared) {
        super.onVisitedVersions(visitor, shared);

        _writer.storeBuffer(shared);
    }
コード例 #7
0
 private final byte[] writeObject(Object object) {
     _writer.write(object);
     byte[] data = new byte[_writer.getOffset()];
     PlatformAdapter.arraycopy(_writer.getBuffer(), 0, data, 0, data.length);
     return data;
 }