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);
}
}
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);
}
}
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));
}
}
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");
}
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);
}
}
Aggregations