@Test public void testAppend() throws IOException { final int COL_COUNT = 10; final byte [] tableName = Bytes.toBytes("tablename"); final byte [] row = Bytes.toBytes("row"); Reader reader = null; HLog log = new HLog(fs, dir, oldLogDir, conf); try { long timestamp = System.currentTimeMillis(); WALEdit cols = new WALEdit(); for (int i = 0; i < COL_COUNT; i++) { cols.add(new KeyValue(row, Bytes.toBytes("column"), Bytes.toBytes(Integer.toString(i)), timestamp, new byte[] { (byte)(i + '0') })); } HRegionInfo hri = new HRegionInfo(new HTableDescriptor(tableName), HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW); log.append(hri, tableName, cols, System.currentTimeMillis()); long logSeqId = log.startCacheFlush(); log.completeCacheFlush(hri.getEncodedNameAsBytes(), tableName, logSeqId, false); log.close(); Path filename = log.computeFilename(); log = null; reader = HLog.getReader(fs, filename, conf); HLog.Entry entry = reader.next(); assertEquals(COL_COUNT, entry.getEdit().size()); int idx = 0; for (KeyValue val : entry.getEdit().getKeyValues()) { assertTrue(Bytes.equals(hri.getEncodedNameAsBytes(), entry.getKey().getEncodedRegionName())); assertTrue(Bytes.equals(tableName, entry.getKey().getTablename())); assertTrue(Bytes.equals(row, val.getRow())); assertEquals((byte)(idx + '0'), val.getValue()[0]); System.out.println(entry.getKey() + " " + val); idx++; } entry = reader.next(); assertEquals(1, entry.getEdit().size()); for (KeyValue val : entry.getEdit().getKeyValues()) { assertTrue(Bytes.equals(hri.getEncodedNameAsBytes(), entry.getKey().getEncodedRegionName())); assertTrue(Bytes.equals(tableName, entry.getKey().getTablename())); assertTrue(Bytes.equals(HLog.METAROW, val.getRow())); assertTrue(Bytes.equals(HLog.METAFAMILY, val.getFamily())); assertEquals(0, Bytes.compareTo(HLog.COMPLETE_CACHE_FLUSH, val.getValue())); System.out.println(entry.getKey() + " " + val); } } finally { if (log != null) { log.closeAndDelete(); } if (reader != null) { reader.close(); } } }
public void append(HRegionInfo regionInfo, WALEdit logEdit, final long now, final boolean isMetaRegion) throws IOException { byte [] regionName = regionInfo.getEncodedNameAsBytes(); byte [] tableName = regionInfo.getTableDesc().getName(); this.append(regionInfo, makeKey(regionName, tableName, -1, now), logEdit); }
HLog implements Syncable { public void append(HRegionInfo regionInfo, WALEdit logEdit, final long now, final boolean isMetaRegion) throws IOException { byte [] regionName = regionInfo.getEncodedNameAsBytes(); byte [] tableName = regionInfo.getTableDesc().getName(); this.append(regionInfo, makeKey(regionName, tableName, -1, now), logEdit); } }
HLog implements Syncable { public void append(HRegionInfo regionInfo, WALEdit logEdit, final long now, final boolean isMetaRegion) throws IOException { byte [] regionName = regionInfo.getEncodedNameAsBytes(); byte [] tableName = regionInfo.getTableDesc().getName(); this.append(regionInfo, makeKey(regionName, tableName, -1, now), logEdit); } HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
              final Configuration conf);  HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
      final Configuration conf, final List<WALObserver> listeners,
      final String prefix);  HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
      final Configuration conf, final List<WALObserver> listeners,
      final boolean failIfLogDirExists, final String prefix); }
HLog implements Syncable { public void append(HRegionInfo regionInfo, WALEdit logEdit, final long now, final boolean isMetaRegion) throws IOException { byte [] regionName = regionInfo.getEncodedNameAsBytes(); byte [] tableName = regionInfo.getTableDesc().getName(); this.append(regionInfo, makeKey(regionName, tableName, -1, now), logEdit); } HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
              final Configuration conf);  HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
      final Configuration conf, final List<WALObserver> listeners,
      final String prefix);  HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
      final Configuration conf, final List<WALObserver> listeners,
      final boolean failIfLogDirExists, final String prefix); static long getWriteOps(); static long getWriteTime(); static long getSyncOps(); static long getSyncTime(); void registerWALActionsListener(final WALObserver listener); boolean unregisterWALActionsListener(final WALObserver listener); long getFilenum(); void setSequenceNumber(final long newvalue); long getSequenceNumber(); byte [][] rollWriter(); static Reader getReader(final FileSystem fs,
    final Path path, Configuration conf); static Writer createWriter(final FileSystem fs,
      final Path path, Configuration conf); void closeAndDelete(); void close(); void append(HRegionInfo regionInfo, WALEdit logEdit,
    final long now,
    final boolean isMetaRegion); void append(HRegionInfo regionInfo, HLogKey logKey, WALEdit logEdit); void append(HRegionInfo info, byte [] tableName, WALEdit edits,
    final long now); void sync(); void hsync(); long startCacheFlush(); void completeCacheFlush(final byte [] encodedRegionName,
      final byte [] tableName, final long logSeqId, final boolean isMetaRegion); void abortCacheFlush(); static boolean isMetaFamily(byte [] family); @SuppressWarnings("unchecked") static Class<? extends HLogKey> getKeyClass(Configuration conf); static HLogKey newKey(Configuration conf); static String getHLogDirectoryName(HServerInfo info); static String getHLogDirectoryName(String serverAddress,
      long startCode); static String getHLogDirectoryName(String serverName); static boolean validateHLogFilename(String filename); static NavigableSet<Path> getSplitEditFilesSorted(final FileSystem fs,
      final Path regiondir); static Path moveAsideBadEditsFile(final FileSystem fs,
      final Path edits); static Path getRegionDirRecoveredEditsDir(final Path regiondir); static void main(String[] args); }
HLog implements Syncable { public void append(HRegionInfo regionInfo, WALEdit logEdit, final long now, final boolean isMetaRegion) throws IOException { byte [] regionName = regionInfo.getEncodedNameAsBytes(); byte [] tableName = regionInfo.getTableDesc().getName(); this.append(regionInfo, makeKey(regionName, tableName, -1, now), logEdit); } HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
              final Configuration conf);  HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
      final Configuration conf, final List<WALObserver> listeners,
      final String prefix);  HLog(final FileSystem fs, final Path dir, final Path oldLogDir,
      final Configuration conf, final List<WALObserver> listeners,
      final boolean failIfLogDirExists, final String prefix); static long getWriteOps(); static long getWriteTime(); static long getSyncOps(); static long getSyncTime(); void registerWALActionsListener(final WALObserver listener); boolean unregisterWALActionsListener(final WALObserver listener); long getFilenum(); void setSequenceNumber(final long newvalue); long getSequenceNumber(); byte [][] rollWriter(); static Reader getReader(final FileSystem fs,
    final Path path, Configuration conf); static Writer createWriter(final FileSystem fs,
      final Path path, Configuration conf); void closeAndDelete(); void close(); void append(HRegionInfo regionInfo, WALEdit logEdit,
    final long now,
    final boolean isMetaRegion); void append(HRegionInfo regionInfo, HLogKey logKey, WALEdit logEdit); void append(HRegionInfo info, byte [] tableName, WALEdit edits,
    final long now); void sync(); void hsync(); long startCacheFlush(); void completeCacheFlush(final byte [] encodedRegionName,
      final byte [] tableName, final long logSeqId, final boolean isMetaRegion); void abortCacheFlush(); static boolean isMetaFamily(byte [] family); @SuppressWarnings("unchecked") static Class<? extends HLogKey> getKeyClass(Configuration conf); static HLogKey newKey(Configuration conf); static String getHLogDirectoryName(HServerInfo info); static String getHLogDirectoryName(String serverAddress,
      long startCode); static String getHLogDirectoryName(String serverName); static boolean validateHLogFilename(String filename); static NavigableSet<Path> getSplitEditFilesSorted(final FileSystem fs,
      final Path regiondir); static Path moveAsideBadEditsFile(final FileSystem fs,
      final Path edits); static Path getRegionDirRecoveredEditsDir(final Path regiondir); static void main(String[] args); static final byte [] METAFAMILY; static final long FIXED_OVERHEAD; }