org.eclipse.jgit.storage.dht.spi.memory
Class MemTable

java.lang.Object
  extended by org.eclipse.jgit.storage.dht.spi.memory.MemTable

public class MemTable
extends java.lang.Object

Tiny in-memory NoSQL style table.

This table is thread-safe, but not very efficient. It uses a single lock to protect its internal data structure from concurrent access, and stores all data as byte arrays. To reduce memory usage, the arrays passed by the caller during put or compareAndSet are used as-is in the internal data structure, and may be returned later. Callers should not modify byte arrays once they are stored in the table, or when obtained from the table.


Nested Class Summary
static class MemTable.Cell
          A cell value in a column.
 
Constructor Summary
MemTable()
          Initialize an empty table.
 
Method Summary
 boolean compareAndSet(byte[] row, byte[] col, byte[] oldVal, byte[] newVal)
          Compare and put or delete a cell.
 void delete(byte[] row, byte[] col)
          Delete a cell.
 void deleteRow(byte[] row)
          Delete an entire row.
 MemTable.Cell get(byte[] row, byte[] col)
          Get a single cell, or null.
 void put(byte[] row, byte[] col, byte[] val)
          Put a value into a cell.
 java.lang.Iterable<MemTable.Cell> scanFamily(byte[] row, ColumnMatcher family)
          Scan all cells in a row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemTable

public MemTable()
Initialize an empty table.

Method Detail

put

public void put(byte[] row,
                byte[] col,
                byte[] val)
Put a value into a cell.

Parameters:
row -
col -
val -

deleteRow

public void deleteRow(byte[] row)
Delete an entire row.

Parameters:
row -

delete

public void delete(byte[] row,
                   byte[] col)
Delete a cell.

Parameters:
row -
col -

compareAndSet

public boolean compareAndSet(byte[] row,
                             byte[] col,
                             byte[] oldVal,
                             byte[] newVal)
Compare and put or delete a cell.

This method performs an atomic compare-and-swap operation on the named cell. If the cell does not yet exist, it will be created. If the cell exists, it will be replaced, and if newVal is null, the cell will be deleted.

Parameters:
row -
col -
oldVal - if null, the cell must not exist, otherwise the cell's current value must exactly equal this value for the update to occur.
newVal - if null, the cell will be removed, otherwise the cell will be created or updated to this value.
Returns:
true if successful, false if oldVal does not match.

get

public MemTable.Cell get(byte[] row,
                         byte[] col)
Get a single cell, or null.

Parameters:
row -
col -
Returns:
the cell, or null.

scanFamily

public java.lang.Iterable<MemTable.Cell> scanFamily(byte[] row,
                                                    ColumnMatcher family)
Scan all cells in a row.

Parameters:
row - the row to scan.
family - if not null, the family to filter and return.
Returns:
iterator for the cells. Cells may appear in any order, including random. Never null.


Copyright © 2011. All Rights Reserved.