Search in sources :

Example 1 with BFile

use of org.exist.storage.index.BFile in project exist by eXist-db.

the class BFileRecoverTest method add.

@Test
public void add() throws EXistException, IOException, BTreeException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager mgr = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        broker.flush();
        broker.sync(Sync.MAJOR);
        final BFile collectionsDb = (BFile) ((NativeBroker) broker).getStorage(NativeBroker.COLLECTIONS_DBX_ID);
        BrokerPool.FORCE_CORRUPTION = true;
        try (final Txn txn = mgr.beginTransaction()) {
            for (int i = 1; i < 1001; i++) {
                String value = "test" + i;
                byte[] data = value.getBytes(UTF_8);
                collectionsDb.put(txn, new Value(data), new FixedByteArray(data, 0, data.length), true);
            }
            byte[] replacement = "new value".getBytes(UTF_8);
            for (int i = 1; i < 101; i++) {
                String value = "test" + i;
                byte[] data = value.getBytes(UTF_8);
                collectionsDb.put(txn, new Value(data), new FixedByteArray(replacement, 0, replacement.length), true);
            }
            mgr.commit(txn);
        }
        Writer writer = new StringWriter();
        collectionsDb.dump(writer);
    }
}
Also used : StringWriter(java.io.StringWriter) TransactionManager(org.exist.storage.txn.TransactionManager) FixedByteArray(org.exist.util.FixedByteArray) Value(org.exist.storage.btree.Value) Txn(org.exist.storage.txn.Txn) BFile(org.exist.storage.index.BFile) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 2 with BFile

use of org.exist.storage.index.BFile in project exist by eXist-db.

the class BFileOverflowTest method read.

@Test
public void read() throws EXistException {
    BrokerPool.FORCE_CORRUPTION = false;
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        BFile collectionsDb = (BFile) ((NativeBroker) broker).getStorage(NativeBroker.COLLECTIONS_DBX_ID);
        Value key = new Value("test".getBytes());
        Value val = collectionsDb.get(key);
    }
}
Also used : Value(org.exist.storage.btree.Value) BFile(org.exist.storage.index.BFile) Test(org.junit.Test)

Example 3 with BFile

use of org.exist.storage.index.BFile in project exist by eXist-db.

the class Statistics method generateIndexStatistics.

/**
 * Generate index statistics.
 *
 * @param conf the configuration
 * @param indexStats the index stats
 */
public static void generateIndexStatistics(Configuration conf, Map<String, IndexStats> indexStats) {
    final DOMFile dom = (DOMFile) conf.getProperty(DOMFile.CONFIG_KEY_FOR_FILE);
    if (dom != null) {
        indexStats.put(DOMFile.FILE_NAME, new IndexStats(dom));
    }
    BFile db = (BFile) conf.getProperty(CollectionStore.FILE_KEY_IN_CONFIG);
    if (db != null) {
        indexStats.put(CollectionStore.FILE_NAME, new IndexStats(db));
    }
    db = (BFile) conf.getProperty(NativeValueIndex.FILE_KEY_IN_CONFIG);
    if (db != null) {
        indexStats.put(NativeValueIndex.FILE_NAME, new IndexStats(db));
    }
}
Also used : DOMFile(org.exist.storage.dom.DOMFile) IndexStats(org.exist.storage.IndexStats) BFile(org.exist.storage.index.BFile)

Example 4 with BFile

use of org.exist.storage.index.BFile in project exist by eXist-db.

the class XMLStatistics method genBufferStatus.

private void genBufferStatus(BrokerPool instance) throws SAXException {
    final AttributesImpl atts = new AttributesImpl();
    this.contentHandler.startElement(NAMESPACE, "buffers", PREFIX + ":buffers", atts);
    final Configuration conf = instance.getConfiguration();
    BFile db;
    db = (BFile) conf.getProperty(CollectionStore.FILE_KEY_IN_CONFIG);
    genBufferDetails(db.getIndexBufferStats(), db.getDataBufferStats(), "Collections storage (" + FileUtils.fileName(db.getFile()) + ")");
    final DOMFile dom = (DOMFile) conf.getProperty(DOMFile.CONFIG_KEY_FOR_FILE);
    genBufferDetails(dom.getIndexBufferStats(), dom.getDataBufferStats(), "Resource storage (" + FileUtils.fileName(dom.getFile()) + ")");
    db = (BFile) conf.getProperty(NativeValueIndex.FILE_KEY_IN_CONFIG);
    if (db != null) {
        genBufferDetails(db.getIndexBufferStats(), db.getDataBufferStats(), "Values index (" + FileUtils.fileName(db.getFile()) + ")");
    }
    this.contentHandler.endElement(NAMESPACE, "buffers", PREFIX + ":buffers");
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) Configuration(org.exist.util.Configuration) DOMFile(org.exist.storage.dom.DOMFile) BFile(org.exist.storage.index.BFile)

Example 5 with BFile

use of org.exist.storage.index.BFile in project exist by eXist-db.

the class BFileOverflowTest method add.

@Test
public void add() throws EXistException, IOException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager mgr = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        broker.flush();
        broker.sync(Sync.MAJOR);
        final BFile collectionsDb = (BFile) ((NativeBroker) broker).getStorage(NativeBroker.COLLECTIONS_DBX_ID);
        BrokerPool.FORCE_CORRUPTION = true;
        final Value key = new Value("test".getBytes());
        try (final Txn txn = mgr.beginTransaction()) {
            byte[] data = "_HELLO_YOU_".getBytes();
            collectionsDb.put(txn, key, new FixedByteArray(data, 0, data.length), true);
            for (int i = 1; i < 101; i++) {
                String value = "_HELLO_" + i;
                data = value.getBytes(UTF_8);
                collectionsDb.append(txn, key, new FixedByteArray(data, 0, data.length));
            }
            mgr.commit(txn);
        }
        // start a new transaction that will not be committed and thus undone
        final Txn txn = mgr.beginTransaction();
        for (int i = 1001; i < 2001; i++) {
            String value = "_HELLO_" + i;
            final byte[] data = value.getBytes(UTF_8);
            collectionsDb.append(txn, key, new FixedByteArray(data, 0, data.length));
        }
        collectionsDb.remove(txn, key);
        pool.getJournalManager().get().flush(true, false);
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) FixedByteArray(org.exist.util.FixedByteArray) Value(org.exist.storage.btree.Value) Txn(org.exist.storage.txn.Txn) BFile(org.exist.storage.index.BFile) Test(org.junit.Test)

Aggregations

BFile (org.exist.storage.index.BFile)6 Value (org.exist.storage.btree.Value)4 Test (org.junit.Test)4 StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 DOMFile (org.exist.storage.dom.DOMFile)2 TransactionManager (org.exist.storage.txn.TransactionManager)2 Txn (org.exist.storage.txn.Txn)2 FixedByteArray (org.exist.util.FixedByteArray)2 IndexStats (org.exist.storage.IndexStats)1 Configuration (org.exist.util.Configuration)1 AttributesImpl (org.xml.sax.helpers.AttributesImpl)1