Package com.persistit

Examples of com.persistit.Exchange


        }
    }

    @Override
    protected OnlineCache buildOnlineCache(Session session) {
        Exchange ex = schemaTreeExchange(session);
        try{
            OnlineCache onlineCache = new OnlineCache();

            // Load affected schemas, then remaining schemas and create full AIS.
            ex.clear().append(S_K_ONLINE).append(Key.BEFORE);
            while(ex.next()) {
                long onlineID = ex.getKey().indexTo(-1).decodeLong();
                long generation = ex.getValue().getLong();

                int schemaCount = 0;
                ex.append(S_K_PROTOBUF).append(Key.BEFORE);
                while(ex.next()) {
                    ++schemaCount;
                    String schema = ex.getKey().indexTo(-1).decodeString();
                    Long prev = onlineCache.schemaToOnline.put(schema, onlineID);
                    assert (prev == null) : String.format("%s, %d, %d", schema, prev, onlineID);
                }

                ex.getKey().cut();
                if(generation != -1) {
                    ProtobufReader reader = new ProtobufReader(getTypesRegistry(), getStorageFormatRegistry());
                    loadProtobufChildren(ex, reader, null);
                    loadPrimaryProtobuf(ex, reader, onlineCache.schemaToOnline.keySet());

                    // Reader will have two copies of affected schemas, skip second (i.e. non-online)
                    AkibanInformationSchema newAIS = finishReader(reader);
                    validateAndFreeze(newAIS, generation);
                    buildRowDefs(session, newAIS);
                    onlineCache.onlineToAIS.put(onlineID, newAIS);
                } else if(schemaCount != 0) {
                    throw new IllegalStateException("No generation but had schemas");
                }

                ex.clear().append(S_K_ONLINE).append(onlineID).append(S_K_CHANGE).append(Key.BEFORE);
                while(ex.next()) {
                    int tid = ex.getKey().indexTo(-1).decodeInt();
                    Long prev = onlineCache.tableToOnline.put(tid, onlineID);
                    assert (prev == null) : String.format("%d, %d, %d", tid, prev, onlineID);
                    TableChanges.ChangeSet changeSet = ChangeSetHelper.load(ex.getValue().getByteArray());
                    onlineCache.onlineToChangeSets.put(onlineID, changeSet);
                }

                ex.clear().append(S_K_ONLINE).append(onlineID);
            }

            return onlineCache;
        } catch(PersistitException | RollbackException e) {
            throw wrapPersistitException(session, e);
View Full Code Here


        addCallbacksForAISChange(session);
    }

    @Override
    protected long generateSaveOnlineSessionID(Session session) {
        Exchange ex = schemaTreeExchange(session);
        try {
            long id = ex.getTree().getSeqAccumulator(ACCUMULATOR_INDEX_ONLINE_ID).allocate();
            ex.clear().append(S_K_ONLINE).append(id);
            ex.getValue().put(-1L); // No generation yet
            ex.store();
            return id;
        } catch(PersistitException | RollbackException e) {
            throw wrapPersistitException(session, e);
        } finally {
            treeService.releaseExchange(session, ex);
View Full Code Here

                            ex.getValue().setStreamMode(false);
                            ex.remove();

                            LOG.debug("Removing delayed tree {} from timestamp {}", treeName, timestamp);
                            TreeLink link = treeService.treeLink(treeName);
                            Exchange ex2 = treeService.getExchange(session, link);
                            ex2.removeTree();
                            treeService.releaseExchange(session, ex2);

                            // Keep consistent if called during runtime
                            if(nameGenerator != null) {
                                nameGenerator.removeTreeName(treeName);
View Full Code Here

            aisMap.releaseShared();
        }
    }

    private Accumulator.SeqAccumulator getGenerationAccumulator(Session session) throws PersistitException {
        Exchange ex = schemaTreeExchange(session);
        try {
            return ex.getTree().getSeqAccumulator(ACCUMULATOR_INDEX_SCHEMA_GEN);
        } finally {
            treeService.releaseExchange(session, ex);
        }
    }
View Full Code Here

     * Tree being removed will cause cache clear on release.
     * However, Trees aren't normally removed as they are non-transactional in < Persistit 3.3.0.
     */
    @Test
    public void invalidTreeClearsCache() throws Exception {
        final Exchange ex1 = treeService.getExchange(session(), new TestLink("schema", "someTree"));
        final Tree tree = ex1.getTree();
        treeService.releaseExchange(session(), ex1);
        assertFalse(treeService.exchangeQueue(session(), ex1.getTree()).isEmpty());
        final Exchange ex2 = treeService.getExchange(session(), new TestLink("schema", "someTree"));
        final Exchange ex3 = treeService.getExchange(session(), new TestLink("schema", "someTree"));
        treeService.releaseExchange(session(), ex3);
        assertEquals("cached exchange count", 1, getCachedExchangeCount(tree));
        ex2.removeTree();
        treeService.releaseExchange(session(), ex2);
        assertEquals("cached exchange queue", null, treeService.exchangeQueue(session(), tree));
View Full Code Here

    /** As {@link #invalidTreeClearsCache} but Store level removal also busts cache. */
    @Test
    public void storeRemoveTreeClearsCache() {
        PersistitStorageDescription desc = createDescription("tree");
        final Exchange ex1 = treeService.getExchange(session(), desc);
        final Exchange ex2 = treeService.getExchange(session(), desc);
        treeService.releaseExchange(session(), ex1);
        treeService.releaseExchange(session(), ex2);
        assertEquals("cached exchange count", 2, getCachedExchangeCount(ex1.getTree()));
        store().removeTree(session(), desc.getObject());
        assertEquals("cached exchange count", 0, getCachedExchangeCount(ex1.getTree()));
View Full Code Here

    @Test
    public void maxTreeCache() {
        for(int i = 0; i < (MAX_EXCHANGE_CACHE * 5); ++i) {
            PersistitStorageDescription desc = createDescription("tree_" + i);
            Exchange ex = treeService.getExchange(session(), desc);
            treeService.releaseExchange(session(), ex);
        }
        assertEquals("cached tree count", MAX_TREE_CACHE, treeService.getCachedTreeCount(session()));
    }
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.