Exemplo n.º 1
0
  /**
   * This procedure runs on the unisolated index. The raw data is written directly onto the {@link
   * Journal} and the index is added/updated using the given file, version and block and the address
   * of the block's data on the {@link Journal}.
   *
   * @return A {@link Boolean} whose value is <code>true</code> iff the block was overwritten.
   */
  @Override
  public Object apply(final IIndex ndx) {

    // tunnel through to the backing journal.
    final AbstractJournal journal = (AbstractJournal) ((AbstractBTree) ndx).getStore();

    // obtain the thread-local key builder for that journal.
    final IKeyBuilder keyBuilder = ndx.getIndexMetadata().getKeyBuilder();

    /*
     * Write the block on the journal, obtaining the address at which it
     * was written - use 0L as the address for an empty block.
     */
    final long addr = len == 0 ? 0L : journal.write(ByteBuffer.wrap(b, off, len));

    // form the key for the index entry for this block.
    final byte[] key =
        keyBuilder
            .reset()
            .appendText(id, true /* unicode */, false /* successor */)
            .append(version)
            .append(block)
            .getKey();

    // record the address of the block in the index.
    final boolean overwrite;
    {
      final DataOutputBuffer out = new DataOutputBuffer(Bytes.SIZEOF_LONG);

      // encode the value for the entry.
      out.reset().putLong(addr);

      final byte[] val = out.toByteArray();

      // insert the entry into the index.
      overwrite = ndx.insert(key, val) != null;
    }

    log.info(
        "Wrote "
            + len
            + " bytes : id="
            + id
            + ", version="
            + version
            + ", block#="
            + block
            + " @ addr"
            + journal.toString(addr)
            + ", overwrite="
            + overwrite);

    return Boolean.valueOf(overwrite);
  }
Exemplo n.º 2
0
  //    @SuppressWarnings("unchecked")
  @Override
  public void remove() {

    if (lastVisited == -1) throw new IllegalStateException();

    //        /*
    //         * Use the last tuple actually visited for the source cursor that
    //         * materialized the tuple to be removed.
    //         */
    //        final ITuple tuple = ((ITupleCursor2)sourceIterator[lastVisited]).tuple();
    //
    //        assert tuple != null;
    //
    //        if(!tuple.getKeysRequested()) {
    //
    //            throw new UnsupportedOperationException("KEYS not specified");
    //
    //        }
    //
    //        final byte[] key = tuple.getKey();

    // the last key visited by the fused iterator.
    final byte[] key = lastKeyBuffer.getKey();

    /*
     * Assuming that the ctor was given the FusedView, this will cause a
     * deleted marker to be written on the first index in the fused view for
     * this key. This is the correct semantics for deleting a tuple from a
     * fused view.
     */

    ndx.remove(key);
  }
    public boolean resolveConflict(IIndex writeSet, ITuple txTuple, ITuple currentTuple)
        throws Exception {

      // The key must be the same for both tuples.
      assertEquals(txTuple.getKey(), currentTuple.getKey());

      // the key for the conflicting writes.
      final byte[] key = txTuple.getKey();

      assertEquals("key", expectedKey, key);

      writeSet.insert(key, resolvedValue);

      return true;
    }