Ejemplo n.º 1
0
 @Override
 public void apply() throws ConnectException {
   try {
     if (!storage.exists(logFile)) {
       return;
     }
     acquireLease();
     if (reader == null) {
       reader = new WALFile.Reader(conf, Reader.file(new Path(logFile)));
     }
     Map<WALEntry, WALEntry> entries = new HashMap<>();
     WALEntry key = new WALEntry();
     WALEntry value = new WALEntry();
     while (reader.next(key, value)) {
       String keyName = key.getName();
       if (keyName.equals(beginMarker)) {
         entries.clear();
       } else if (keyName.equals(endMarker)) {
         for (Map.Entry<WALEntry, WALEntry> entry : entries.entrySet()) {
           String tempFile = entry.getKey().getName();
           String committedFile = entry.getValue().getName();
           if (!storage.exists(committedFile)) {
             storage.commit(tempFile, committedFile);
           }
         }
       } else {
         WALEntry mapKey = new WALEntry(key.getName());
         WALEntry mapValue = new WALEntry(value.getName());
         entries.put(mapKey, mapValue);
       }
     }
   } catch (IOException e) {
     throw new ConnectException(e);
   }
 }
Ejemplo n.º 2
0
  private void verify2Values(Path file) throws IOException {
    WALEntry key1 = new WALEntry("key1");
    WALEntry val1 = new WALEntry("val1");

    WALEntry key2 = new WALEntry("key2");
    WALEntry val2 = new WALEntry("val2");

    WALFile.Reader reader = new WALFile.Reader(conf, WALFile.Reader.file(file));

    assertEquals(key1.getName(), ((WALEntry) reader.next((Object) null)).getName());
    assertEquals(val1.getName(), ((WALEntry) reader.getCurrentValue((Object) null)).getName());
    assertEquals(key2.getName(), ((WALEntry) reader.next((Object) null)).getName());
    assertEquals(val2.getName(), ((WALEntry) reader.getCurrentValue((Object) null)).getName());
    assertNull(reader.next((Object) null));
    reader.close();
  }
Ejemplo n.º 3
0
 @Override
 public void close() throws ConnectException {
   try {
     if (writer != null) {
       writer.close();
       writer = null;
     }
     if (reader != null) {
       reader.close();
       reader = null;
     }
   } catch (IOException e) {
     throw new ConnectException("Error closing " + logFile, e);
   }
 }