Package com.persistit

Examples of com.persistit.Exchange


        this.securityService = securityService;
    }

    @Override
    public void addOnlineHandledHKey(Session session, int tableID, Key hKey) {
        Exchange ex = onlineHandledHKeyExchange(session, tableID);
        try {
            ex.clear().getKey().appendByteArray(hKey.getEncodedBytes(), 0, hKey.getEncodedSize());
            ex.store();
        } catch(PersistitException | RollbackException e) {
            throw wrapPersistitException(session, e);
        } finally {
            treeService.releaseExchange(session, ex);
        }
View Full Code Here


        }
    }

    @Override
    public Iterator<byte[]> getOnlineHandledHKeyIterator(final Session session, int tableID, Key hKey) {
        final Exchange ex = onlineHandledHKeyExchange(session, tableID);
        if(hKey != null) {
            ex.clear().getKey().appendByteArray(hKey.getEncodedBytes(), 0, hKey.getEncodedSize());
        }
        return new Iterator<byte[]>() {
            private Key.Direction dir = Key.GTEQ;

            @Override
            public boolean hasNext() {
                throw new UnsupportedOperationException();
            }

            @Override
            public byte[] next() {
                try {
                    if(!ex.traverse(dir, true)) {
                        return null;
                    }
                    dir = Direction.GT;
                    return ex.getKey().decodeByteArray();
                } catch(PersistitException | RollbackException e) {
                    throw wrapPersistitException(session, e);
                }
            }
View Full Code Here

    }

    @Override
    public void setOnlineDMLError(Session session, int tableID, String message) {
        OnlineSession onlineSession = getOnlineSession(session, true);
        Exchange ex = schemaTreeExchange(session);
        try {
            ex.clear().append(S_K_ONLINE).append(onlineSession.id).append(S_K_ERROR);
            ex.getValue().putString(message);
            ex.store();
        } catch(PersistitException | RollbackException e) {
            if(ex != null) {
                treeService.releaseExchange(session, ex);
            }
            throw wrapPersistitException(session, e);
View Full Code Here

    }

    @Override
    public String getOnlineDMLError(Session session) {
        OnlineSession onlineSession = getOnlineSession(session, true);
        Exchange ex = schemaTreeExchange(session);
        try {
            ex.clear().append(S_K_ONLINE).append(onlineSession.id).append(S_K_ERROR);
            ex.fetch();
            // write skew
            ex.lock();
            return ex.getValue().isDefined() ? ex.getValue().getString() : null;
        } catch(PersistitException | RollbackException e) {
            if(ex != null) {
                treeService.releaseExchange(session, ex);
            }
            throw wrapPersistitException(session, e);
View Full Code Here

    @Override
    public void addOnlineChangeSet(Session session, ChangeSet changeSet) {
        OnlineSession onlineSession = getOnlineSession(session, true);
        onlineSession.tableIDs.add(changeSet.getTableId());
        Exchange ex = schemaTreeExchange(session);
        try {
            ex.clear().append(S_K_ONLINE).append(onlineSession.id).append(S_K_CHANGE).append(changeSet.getTableId());
            ex.getValue().putByteArray(ChangeSetHelper.save(changeSet));
            ex.store();
        } catch(PersistitException | RollbackException e) {
            if(ex != null) {
                treeService.releaseExchange(session, ex);
            }
            throw wrapPersistitException(session, e);
View Full Code Here

    }

    void treeWasRemoved(Session session, String schema, String treeName) {
        LOG.debug("Delaying removal of tree (until next restart): {}", treeName);
        delayedTreeCount.incrementAndGet();
        Exchange ex = schemaTreeExchange(session);
        try {
            long id = delayedTreeIDGenerator.incrementAndGet();
            long timestamp = System.currentTimeMillis();
            ex.clear().append(S_K_DELAYED).append(id).append(timestamp);
            ex.getValue().setStreamMode(true);
            ex.getValue().put(schema);
            ex.getValue().put(treeName);
            ex.getValue().setStreamMode(false);
            ex.store();
        } catch(PersistitException | RollbackException e) {
            throw wrapPersistitException(session, e);
        } finally {
            treeService.releaseExchange(session, ex);
        }
View Full Code Here

    @Override
    protected void storedAISChange(Session session,
                                   AkibanInformationSchema newAIS,
                                   Collection<String> schemaNames) {
        ByteBuffer buffer = null;
        Exchange ex = null;
        try {
            createValidatedShared(session, newAIS, GenValue.NEW, GenMap.NO_PUT);

            for(String schema : schemaNames) {
                ex = schemaTreeExchange(session);
                saveMetaAndDataVersions(ex);
                ex.clear().append(S_K_PROTOBUF).append(schema);
                buffer = storeProtobuf(ex, buffer, newAIS, schema);
                treeService.releaseExchange(session, ex);
                ex = null;
            }
            buildRowDefs(session, newAIS);
View Full Code Here

            }
        }
    }

    private void serializeMemoryTables(Session session, AkibanInformationSchema newAIS) {
        Exchange ex = null;
        try {
            ex = schemaTreeExchange(session);
            saveMemoryTables(ex, newAIS);
            treeService.releaseExchange(session, ex);
            ex = null;
View Full Code Here

    @Override
    protected void storedOnlineChange(Session session,
                                      OnlineSession onlineSession,
                                      AkibanInformationSchema newAIS,
                                      Collection<String> schemas) {
        Exchange ex = schemaTreeExchange(session);
        try {
            // Get a unique generation for this AIS, but will only be visible to owning session
            createValidatedShared(session, newAIS, GenValue.NEW, GenMap.NO_PUT);

            // And a new generation for the current so no one else will think the one for newAIS is theirs
            getNextGeneration(session);

            saveMetaAndDataVersions(ex);

            // online,cid => generation
            ex.clear().append(S_K_ONLINE).append(onlineSession.id);
            ex.getValue().put(newAIS.getGeneration());
            ex.store();

            // online,cid,protobuf,schema = bytes
            ByteBuffer buffer = null;
            ex.append(S_K_PROTOBUF).append("");
            for(String name : schemas) {
                ex.to(name);
                buffer = storeProtobuf(ex, buffer, newAIS, name);
            }

            addCallbacksForAISChange(session);
        } catch(PersistitException | RollbackException e) {
View Full Code Here

        }
    }

    @Override
    protected void clearOnlineState(Session session, OnlineSession onlineSession) {
        Exchange ex = schemaTreeExchange(session);
        try {
            ex.clear().append(S_K_ONLINE).append(onlineSession.id);
            ex.remove(Key.GTEQ);
            for(int tid : onlineSession.tableIDs) {
                String treeName = onlineHandledHKeyTreeName(onlineSession.id, tid);
                if(treeService.treeExists(treeName)) {
                    Exchange changeEx = onlineHandledHKeyExchange(session, onlineSession.id, tid);
                    //
                    // remove() would be preferable but Persistit will block until transactions
                    // and journal can be fully pruned. Instead, clear and track for delayed.
                    //
                    changeEx.removeAll();
                    nameGenerator.generatedTreeName(treeName);
                    treeWasRemoved(session, SCHEMA_TREE_NAME, treeName);
                }
            }
        } catch(PersistitException | RollbackException e) {
View Full Code Here

TOP

Related Classes of com.persistit.Exchange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.