Examples of WriteBatch


Examples of org.iq80.leveldb.WriteBatch

                                    null,
                                    new String(rawJournalValue));

                    String streamKey = loggedJournalEntry.nextMetadataValue();

                    WriteBatch batch = this.database().createWriteBatch();

                    try {
                        batch.delete(streamKey.getBytes());
                        batch.delete(journalKey);
                        this.database().write(batch);

                        System.out.println(
                                "Repaired journal entry: "
                                + journalSequence
                                + " and stream entry: "
                                + streamKey);

                    } catch (Throwable t) {
                        System.out.println(
                                "Could not repair journal entry: "
                                + journalSequence
                                + " and stream entry: "
                                + streamKey);
                    } finally {
                        try {
                            batch.close();
                        } catch (Throwable t) {
                            // ignore
                        }
                    }
                }
View Full Code Here

Examples of org.iq80.leveldb.WriteBatch

        return this.databasePath;
    }

    public void logEntries(LoggableJournalEntry[] aJournalEntries) {

        WriteBatch batch = this.database().createWriteBatch();

        try {
            synchronized (this.lockFor(aJournalEntries[0].primaryResourceName())) {
                for (LoggableJournalEntry journalEntry : aJournalEntries) {

                    long journalSequence = this.nextJournalSequence();

                    this.confirmNonExistingReference(journalEntry.referenceKey());

                    String jounralKey =
                            JournalKeyProvider.ES_JOURNAL_PREFIX_KEY
                            + journalSequence;

                    String referenceKey =
                            journalEntry.referenceKey();

                    byte[] journalSequenceBytes = (""+journalSequence).getBytes();

                    String journalValue =
                            this.valueWithMetadata(
                                    journalEntry.value(),
                                    referenceKey);

                    // journal entry points to reference

                    batch.put(
                            jounralKey.getBytes(),
                            journalValue.getBytes());

                    // reference points to journal entry

                    batch.put(
                            referenceKey.getBytes(),
                            journalSequenceBytes);
                }

                this.database().write(batch);
            }

        } catch (Throwable t) {
            throw new EventStoreAppendException(
                    "Could not append to journal because: "
                            + t.getMessage(),
                    t);
        } finally {
            try {
                batch.close();
            } catch (Throwable t) {
                // ignore
            }
        }
    }
View Full Code Here

Examples of org.iq80.leveldb.WriteBatch

        // open new db
        Options options = new Options().createIfMissing(true);
        DB db = new Iq80DBFactory().open(databaseDir, options);

        // write an empty batch
        WriteBatch batch = db.createWriteBatch();
        batch.close();
        db.write(batch);

        // close the db
        db.close();
View Full Code Here

Examples of org.iq80.leveldb.WriteBatch

        if (numEntries != num) {
            message = String.format("(%d ops)", numEntries);
        }

        for (int i = 0; i < numEntries; i += entriesPerBatch) {
            WriteBatch batch = db.createWriteBatch();
            for (int j = 0; j < entriesPerBatch; j++) {
                int k = (order == SEQUENTIAL) ? i + j : random.nextInt(num);
                byte[] key = formatNumber(k);
                batch.put(key, generator.generate(valueSize));
                bytes += valueSize + key.length;
                finishedSingleOp();
            }
            db.write(batch, writeOptions);
            batch.close();
        }
    }
View Full Code Here

Examples of org.rocksdb.WriteBatch

            new Tuple<>("k2".getBytes(), "v22".getBytes())));
        testEvents.add(new Tuple<>(Action.DELETE,
            new Tuple<byte[], byte[]>("k3".getBytes(), null)));

        // load test data to the write batch
        final WriteBatch batch = new WriteBatch();
        for(final Tuple<Action, Tuple<byte[], byte[]>> testEvent : testEvents) {
            final Tuple<byte[], byte[]> data = testEvent.value;
            switch(testEvent.key) {

                case PUT:
                    batch.put(data.key, data.value);
                    break;

                case MERGE:
                    batch.merge(data.key, data.value);
                    break;

                case DELETE:
                    batch.remove(data.key);
                    break;

                case LOG:
                    batch.putLogData(data.value);
                    break;
            }
        }

        // attempt to read test data back from the WriteBatch by iterating with a handler
        final CapturingWriteBatchHandler handler = new CapturingWriteBatchHandler();
        batch.iterate(handler);

        // compare the results to the test data
        final List<Tuple<Action, Tuple<byte[], byte[]>>> actualEvents = handler.getEvents();
        assertThat(testEvents.size()).isSameAs(actualEvents.size());
View Full Code Here

Examples of org.rocksdb.WriteBatch

  @Rule
  public TemporaryFolder dbFolder = new TemporaryFolder();

  @Test
  public void emptyWriteBatch() {
    WriteBatch batch = new WriteBatch();
    assertThat(batch.count()).isEqualTo(0);
  }
View Full Code Here

Examples of org.rocksdb.WriteBatch

  }

  @Test
  public void multipleBatchOperations()
      throws UnsupportedEncodingException {
    WriteBatch batch =  new WriteBatch();
    batch.put("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
    batch.remove("box".getBytes("US-ASCII"));
    batch.put("baz".getBytes("US-ASCII"), "boo".getBytes("US-ASCII"));
    WriteBatchInternal.setSequence(batch, 100);
    assertThat(WriteBatchInternal.sequence(batch)).
        isNotNull().
        isEqualTo(100);
    assertThat(batch.count()).isEqualTo(3);
    assertThat(new String(getContents(batch), "US-ASCII")).
        isEqualTo("Put(baz, boo)@102" +
                  "Delete(box)@101" +
                  "Put(foo, bar)@100");
  }
View Full Code Here

Examples of org.rocksdb.WriteBatch

  }

  @Test
  public void testAppendOperation()
      throws UnsupportedEncodingException {
    WriteBatch b1 = new WriteBatch();
    WriteBatch b2 = new WriteBatch();
    WriteBatchInternal.setSequence(b1, 200);
    WriteBatchInternal.setSequence(b2, 300);
    WriteBatchInternal.append(b1, b2);
    assertThat(getContents(b1).length).isEqualTo(0);
    assertThat(b1.count()).isEqualTo(0);
    b2.put("a".getBytes("US-ASCII"), "va".getBytes("US-ASCII"));
    WriteBatchInternal.append(b1, b2);
    assertThat("Put(a, va)@200".equals(new String(getContents(b1), "US-ASCII")));
    assertThat(b1.count()).isEqualTo(1);
    b2.clear();
    b2.put("b".getBytes("US-ASCII"), "vb".getBytes("US-ASCII"));
    WriteBatchInternal.append(b1, b2);
    assertThat(("Put(a, va)@200" +
            "Put(b, vb)@201")
                .equals(new String(getContents(b1), "US-ASCII")));
    assertThat(b1.count()).isEqualTo(2);
    b2.remove("foo".getBytes("US-ASCII"));
    WriteBatchInternal.append(b1, b2);
    assertThat(("Put(a, va)@200" +
        "Put(b, vb)@202" +
        "Put(b, vb)@201" +
        "Delete(foo)@203")
View Full Code Here

Examples of org.rocksdb.WriteBatch

  }

  @Test
  public void blobOperation()
      throws UnsupportedEncodingException {
    WriteBatch batch = new WriteBatch();
    batch.put("k1".getBytes("US-ASCII"), "v1".getBytes("US-ASCII"));
    batch.put("k2".getBytes("US-ASCII"), "v2".getBytes("US-ASCII"));
    batch.put("k3".getBytes("US-ASCII"), "v3".getBytes("US-ASCII"));
    batch.putLogData("blob1".getBytes("US-ASCII"));
    batch.remove("k2".getBytes("US-ASCII"));
    batch.putLogData("blob2".getBytes("US-ASCII"));
    batch.merge("foo".getBytes("US-ASCII"), "bar".getBytes("US-ASCII"));
    assertThat(batch.count()).isEqualTo(5);
    assertThat(("Merge(foo, bar)@4" +
            "Put(k1, v1)@0" +
            "Delete(k2)@3" +
            "Put(k2, v2)@1" +
            "Put(k3, v3)@2")
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.