Search in sources :

Example 1 with FixedByteArray

use of org.exist.util.FixedByteArray 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 FixedByteArray

use of org.exist.util.FixedByteArray in project exist by eXist-db.

the class StoreValueLoggable method read.

@Override
public void read(ByteBuffer in) {
    super.read(in);
    page = in.getInt();
    tid = in.getShort();
    final int len = in.getShort();
    final byte[] data = new byte[len];
    in.get(data);
    value = new FixedByteArray(data, 0, len);
}
Also used : FixedByteArray(org.exist.util.FixedByteArray)

Example 3 with FixedByteArray

use of org.exist.util.FixedByteArray in project exist by eXist-db.

the class OverflowAppendLoggable method read.

@Override
public void read(ByteBuffer in) {
    super.read(in);
    pageNum = in.getInt();
    chunkSize = in.getInt();
    final byte[] b = new byte[chunkSize];
    in.get(b);
    data = new FixedByteArray(b);
}
Also used : FixedByteArray(org.exist.util.FixedByteArray)

Example 4 with FixedByteArray

use of org.exist.util.FixedByteArray 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

FixedByteArray (org.exist.util.FixedByteArray)4 Value (org.exist.storage.btree.Value)2 BFile (org.exist.storage.index.BFile)2 TransactionManager (org.exist.storage.txn.TransactionManager)2 Txn (org.exist.storage.txn.Txn)2 Test (org.junit.Test)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1