コード例 #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
ファイル: DumpStore.java プロジェクト: nigelsmall/neo4j
  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
ファイル: LegacyLogsTest.java プロジェクト: lassewesth/neo4j
  @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());
      }
    }
  }
コード例 #4
0
  @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;
  }
コード例 #5
0
 @Override
 public int read(ByteBuffer dst) throws IOException {
   return delegateChannel.read(dst);
 }
コード例 #6
0
 @Override
 public StoreChannel position(long newPosition) throws IOException {
   return delegateChannel.position(newPosition);
 }
コード例 #7
0
 @Override
 public StoreChannel truncate(long size) throws IOException {
   return delegateChannel.truncate(size);
 }
コード例 #8
0
 @Override
 public MappedByteBuffer map(FileChannel.MapMode mode, long position, long size)
     throws IOException {
   return delegateChannel.map(mode, position, size);
 }
コード例 #9
0
 @Override
 public void force(boolean metaData) throws IOException {
   delegateChannel.force(metaData);
 }
コード例 #10
0
 @Override
 public boolean isOpen() {
   return delegateChannel.isOpen();
 }
コード例 #11
0
 @Override
 public void writeAll(ByteBuffer src) throws IOException {
   delegateChannel.writeAll(src);
 }
コード例 #12
0
ファイル: RecordFormat.java プロジェクト: akollegger/neo4j
 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);
 }
コード例 #13
0
 @Override
 public int hashCode() {
   int result = delegateChannel.hashCode();
   result = 31 * result + (int) (version ^ (version >>> 32));
   return result;
 }
コード例 #14
0
 @Override
 public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
   return delegateChannel.read(dsts, offset, length);
 }
コード例 #15
0
 @Override
 public long read(ByteBuffer[] dsts) throws IOException {
   return delegateChannel.read(dsts);
 }
コード例 #16
0
 @Override
 public long write(ByteBuffer[] srcs) throws IOException {
   return delegateChannel.write(srcs);
 }
コード例 #17
0
 @Override
 public long write(ByteBuffer[] srcs, int offset, int length) throws IOException {
   return delegateChannel.write(srcs, offset, length);
 }
コード例 #18
0
 @Override
 public void close() throws IOException {
   delegateChannel.close();
 }
コード例 #19
0
 @Override
 public int write(ByteBuffer src) throws IOException {
   return delegateChannel.write(src);
 }
コード例 #20
0
 @Override
 public FileLock tryLock() throws IOException {
   return delegateChannel.tryLock();
 }
コード例 #21
0
 @Override
 public long position() throws IOException {
   return delegateChannel.position();
 }
コード例 #22
0
 @Override
 public long size() throws IOException {
   return delegateChannel.size();
 }