Пример #1
0
  public int dump(String filenameOrDirectory, PrintStream out, TimeZone timeZone)
      throws IOException {
    int logsFound = 0;
    for (String fileName : filenamesOf(filenameOrDirectory, getLogPrefix())) {
      logsFound++;
      out.println("=== " + fileName + " ===");
      StoreChannel fileChannel = fileSystem.open(new File(fileName), "r");
      ByteBuffer buffer = ByteBuffer.allocateDirect(9 + Xid.MAXGTRIDSIZE + Xid.MAXBQUALSIZE * 10);
      long logVersion, prevLastCommittedTx;
      try {
        long[] header = VersionAwareLogEntryReader.readLogHeader(buffer, fileChannel, false);
        logVersion = header[0];
        prevLastCommittedTx = header[1];
      } catch (IOException ex) {
        out.println("Unable to read timestamp information, no records in logical log.");
        out.println(ex.getMessage());
        fileChannel.close();
        throw ex;
      }
      out.println(
          "Logical log version: "
              + logVersion
              + " with prev committed tx["
              + prevLastCommittedTx
              + "]");

      LogDeserializer deserializer = new LogDeserializer(buffer, instantiateCommandReaderFactory());
      PrintingConsumer consumer = new PrintingConsumer(out, timeZone);

      try (Cursor<LogEntry, IOException> cursor = deserializer.cursor(fileChannel)) {
        while (cursor.next(consumer)) ;
      }
    }
    return logsFound;
  }
Пример #2
0
  private boolean dumpRecord(
      STORE store, int size, StoreChannel fileChannel, ByteBuffer buffer, long id)
      throws Exception {
    RECORD record = store.forceGetRecord(id);

    Object transform = transform(record);
    if (transform != null) {
      if (!"".equals(transform)) {
        out.println(transform);
      }
    } else {
      out.print(record);
      buffer.clear();
      fileChannel.read(buffer, id * size);
      buffer.flip();
      if (record.inUse()) {
        dumpHex(buffer, id * size);
      } else if (allZero(buffer)) {
        out.printf(": all zeros @ 0x%x - 0x%x%n", id * size, (id + 1) * size);
      } else {
        dumpHex(buffer, id * size);
      }
    }

    return record.inUse();
  }
Пример #3
0
  @Test
  public void shouldMoveFiles() throws IOException {
    // given
    final EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction();
    fs.mkdirs(storeDir);
    fs.mkdirs(migrationDir);

    final Set<File> logsInStoreDir =
        new HashSet<>(
            Arrays.asList(
                new File(storeDir, getLegacyLogFilename(1)),
                new File(storeDir, getLegacyLogFilename(2))));

    final List<File> logsInMigrationDir =
        Arrays.asList(
            new File(migrationDir, getLegacyLogFilename(1)),
            new File(migrationDir, getLegacyLogFilename(2)));

    for (File file : logsInMigrationDir) {
      try (StoreChannel channel = fs.create(file)) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putLong(42);
        buffer.flip();
        channel.write(buffer);
      }
    }

    // should override older files
    for (File file : logsInStoreDir) {
      try (StoreChannel channel = fs.create(file)) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        buffer.putLong(13);
        buffer.flip();
        channel.write(buffer);
      }
    }

    // when
    new LegacyLogs(fs, reader, writer).operate(FileOperation.MOVE, migrationDir, storeDir);

    // then
    assertEquals(logsInStoreDir, new HashSet<>(Arrays.asList(fs.listFiles(storeDir))));
    for (File file : logsInStoreDir) {
      try (StoreChannel channel = fs.open(file, "r")) {
        ByteBuffer buffer = ByteBuffer.allocate(8);
        channel.read(buffer);
        buffer.flip();
        assertEquals(42, buffer.getLong());
      }
    }
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    PhysicalLogVersionedStoreChannel that = (PhysicalLogVersionedStoreChannel) o;

    if (version != that.version) {
      return false;
    }
    if (!delegateChannel.equals(that.delegateChannel)) {
      return false;
    }

    return true;
  }
 @Override
 public int read(ByteBuffer dst) throws IOException {
   return delegateChannel.read(dst);
 }
 @Override
 public StoreChannel position(long newPosition) throws IOException {
   return delegateChannel.position(newPosition);
 }
 @Override
 public StoreChannel truncate(long size) throws IOException {
   return delegateChannel.truncate(size);
 }
 @Override
 public MappedByteBuffer map(FileChannel.MapMode mode, long position, long size)
     throws IOException {
   return delegateChannel.map(mode, position, size);
 }
 @Override
 public void force(boolean metaData) throws IOException {
   delegateChannel.force(metaData);
 }
 @Override
 public boolean isOpen() {
   return delegateChannel.isOpen();
 }
 @Override
 public void writeAll(ByteBuffer src) throws IOException {
   delegateChannel.writeAll(src);
 }
Пример #12
0
 public final void writeRecord(Record record, StoreChannel channel) throws IOException {
   ByteBuffer buffer = ByteBuffer.allocate(getRecordSize());
   StubPageCursor cursor = new StubPageCursor(0, buffer);
   write(record, cursor);
   channel.writeAll(buffer);
 }
 @Override
 public int hashCode() {
   int result = delegateChannel.hashCode();
   result = 31 * result + (int) (version ^ (version >>> 32));
   return result;
 }
 @Override
 public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
   return delegateChannel.read(dsts, offset, length);
 }
 @Override
 public long read(ByteBuffer[] dsts) throws IOException {
   return delegateChannel.read(dsts);
 }
 @Override
 public long write(ByteBuffer[] srcs) throws IOException {
   return delegateChannel.write(srcs);
 }
 @Override
 public long write(ByteBuffer[] srcs, int offset, int length) throws IOException {
   return delegateChannel.write(srcs, offset, length);
 }
 @Override
 public void close() throws IOException {
   delegateChannel.close();
 }
 @Override
 public int write(ByteBuffer src) throws IOException {
   return delegateChannel.write(src);
 }
 @Override
 public FileLock tryLock() throws IOException {
   return delegateChannel.tryLock();
 }
 @Override
 public long position() throws IOException {
   return delegateChannel.position();
 }
 @Override
 public long size() throws IOException {
   return delegateChannel.size();
 }