Search in sources :

Example 6 with DOMFile

use of org.exist.storage.dom.DOMFile 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 7 with DOMFile

use of org.exist.storage.dom.DOMFile in project exist by eXist-db.

the class DOMFileRecoverTest method get.

@Test
public void get() throws EXistException, IOException, BTreeException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        // Recover and read the data
        assertNotNull(broker);
        TransactionManager mgr = pool.getTransactionManager();
        assertNotNull(mgr);
        DOMFile domDb = ((NativeBroker) broker).getDOMFile();
        assertNotNull(domDb);
        domDb.setOwnerObject(this);
        IndexQuery query = new IndexQuery(IndexQuery.GT, new NativeBroker.NodeRef(500));
        assertNotNull(query);
        List<?> keys = domDb.findKeys(query);
        assertNotNull(keys);
        int count = 0;
        for (Iterator<?> i = keys.iterator(); i.hasNext(); count++) {
            Value key = (Value) i.next();
            assertNotNull(key);
            Value value = domDb.get(key);
            assertNotNull(value);
        }
        Writer writer = new StringWriter();
        domDb.dump(writer);
    }
}
Also used : IndexQuery(org.exist.storage.btree.IndexQuery) DOMFile(org.exist.storage.dom.DOMFile) StringWriter(java.io.StringWriter) TransactionManager(org.exist.storage.txn.TransactionManager) Value(org.exist.storage.btree.Value) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 8 with DOMFile

use of org.exist.storage.dom.DOMFile in project exist by eXist-db.

the class BTreeRecoverTest method add.

private void add(final BrokerPool pool) throws EXistException, IOException, BTreeException, TerminatedException {
    // Add some random data and force db corruption
    final TransactionManager mgr = pool.getTransactionManager();
    final NodeIdFactory idFact = pool.getNodeFactory();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        broker.flush();
        final DOMFile domDb = ((NativeBroker) broker).getDOMFile();
        domDb.setOwnerObject(this);
        try (final Txn txn = mgr.beginTransaction()) {
            // put 1000 values into the btree
            for (int i = 1; i < 1001; i++) {
                final NodeId id = idFact.createInstance(i);
                domDb.addValue(txn, new NativeBroker.NodeRef(500, id), i);
            }
            final IndexQuery idx = new IndexQuery(IndexQuery.GT, new NativeBroker.NodeRef(500, idFact.createInstance(800)));
            domDb.remove(txn, idx, null);
            mgr.commit(txn);
        }
        // start a dirty, uncommitted transaction. This will be rolled back by the recovery.
        final Txn txn = mgr.beginTransaction();
        for (int i = 801; i < 2001; i++) {
            domDb.addValue(txn, new NativeBroker.NodeRef(500, idFact.createInstance(i)), i);
        }
        for (int i = 101; i < 301; i++) {
            domDb.addValue(txn, new NativeBroker.NodeRef(500, idFact.createInstance(i)), i * 3);
        }
        final IndexQuery idx = new IndexQuery(IndexQuery.GT, new NativeBroker.NodeRef(500, idFact.createInstance(600)));
        domDb.remove(txn, idx, null);
        // DO NOT COMMIT THE TRANSACTION!
        pool.getJournalManager().get().flush(true, false);
    }
}
Also used : NodeIdFactory(org.exist.numbering.NodeIdFactory) IndexQuery(org.exist.storage.btree.IndexQuery) TransactionManager(org.exist.storage.txn.TransactionManager) NodeId(org.exist.numbering.NodeId) DOMFile(org.exist.storage.dom.DOMFile) Txn(org.exist.storage.txn.Txn)

Example 9 with DOMFile

use of org.exist.storage.dom.DOMFile in project exist by eXist-db.

the class BTreeRecoverTest method get.

private void get(final BrokerPool pool) throws EXistException, TerminatedException, IOException, BTreeException {
    final NodeIdFactory idFact = pool.getNodeFactory();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final DOMFile domDb = ((NativeBroker) broker).getDOMFile();
        domDb.setOwnerObject(this);
        final IndexQuery query = new IndexQuery(IndexQuery.GEQ, new NativeBroker.NodeRef(500, idFact.createInstance(1)));
        domDb.query(query, new IndexCallback());
        assertEquals(count, 800);
    }
}
Also used : NodeIdFactory(org.exist.numbering.NodeIdFactory) IndexQuery(org.exist.storage.btree.IndexQuery) DOMFile(org.exist.storage.dom.DOMFile)

Aggregations

DOMFile (org.exist.storage.dom.DOMFile)9 TransactionManager (org.exist.storage.txn.TransactionManager)5 StringWriter (java.io.StringWriter)4 Writer (java.io.Writer)4 IndexQuery (org.exist.storage.btree.IndexQuery)4 Txn (org.exist.storage.txn.Txn)4 NodeId (org.exist.numbering.NodeId)3 NodeIdFactory (org.exist.numbering.NodeIdFactory)3 Test (org.junit.Test)3 Collection (org.exist.collections.Collection)2 Value (org.exist.storage.btree.Value)2 BFile (org.exist.storage.index.BFile)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 BinaryDocument (org.exist.dom.persistent.BinaryDocument)1 LockedDocument (org.exist.dom.persistent.LockedDocument)1 PermissionDeniedException (org.exist.security.PermissionDeniedException)1 EmbeddedXMLStreamReader (org.exist.stax.EmbeddedXMLStreamReader)1