public static CommitLogDescriptor fromFileName(String name) { Matcher matcher; if (!(matcher = COMMIT_LOG_FILE_PATTERN.matcher(name)).matches()) throw new RuntimeException("Cannot parse the version of the file: " + name); if (matcher.group(3) == null) throw new UnsupportedOperationException("Commitlog segment is too old to open; upgrade to 1.2.5+ first"); long id = Long.parseLong(matcher.group(3).split(SEPARATOR)[1]); return new CommitLogDescriptor(Integer.parseInt(matcher.group(2)), id); }
public static CommitLogDescriptor fromFileName(String name) { Matcher matcher; if (!(matcher = COMMIT_LOG_FILE_PATTERN.matcher(name)).matches()) throw new RuntimeException("Cannot parse the version of the file: " + name); if (matcher.group(3) == null) throw new UnsupportedOperationException("Commitlog segment is too old to open; upgrade to 1.2.5+ first"); long id = Long.parseLong(matcher.group(3).split(SEPARATOR)[1]); return new CommitLogDescriptor(Integer.parseInt(matcher.group(2)), id, null, new EncryptionContext()); }
public static CommitLogDescriptor fromFileName(String name) { Matcher matcher; if (!(matcher = COMMIT_LOG_FILE_PATTERN.matcher(name)).matches()) throw new RuntimeException("Cannot parse the version of the file: " + name); if (matcher.group(3) == null) throw new UnsupportedOperationException("Commitlog segment is too old to open; upgrade to 1.2.5+ first"); long id = Long.parseLong(matcher.group(3).split(SEPARATOR)[1]); return new CommitLogDescriptor(Integer.parseInt(matcher.group(2)), id, null, new EncryptionContext()); }
public static CommitLogDescriptor fromFileName(String name) { Matcher matcher; if (!(matcher = COMMIT_LOG_FILE_PATTERN.matcher(name)).matches()) throw new RuntimeException("Cannot parse the version of the file: " + name); if (matcher.group(3) == null) throw new UnsupportedOperationException("Commitlog segment is too old to open; upgrade to 1.2.5+ first"); long id = Long.parseLong(matcher.group(3).split(SEPARATOR)[1]); return new CommitLogDescriptor(Integer.parseInt(matcher.group(2)), id, null, new EncryptionContext()); }
public static CommitLogDescriptor readHeader(DataInput input, EncryptionContext encryptionContext) throws IOException { CRC32 checkcrc = new CRC32(); int version = input.readInt(); updateChecksumInt(checkcrc, version); long id = input.readLong(); updateChecksumInt(checkcrc, (int) (id & 0xFFFFFFFFL)); updateChecksumInt(checkcrc, (int) (id >>> 32)); int parametersLength = 0; if (version >= VERSION_22) { parametersLength = input.readShort() & 0xFFFF; updateChecksumInt(checkcrc, parametersLength); } // This should always succeed as parametersLength cannot be too long even for a // corrupt segment file. byte[] parametersBytes = new byte[parametersLength]; input.readFully(parametersBytes); checkcrc.update(parametersBytes, 0, parametersBytes.length); int crc = input.readInt(); if (crc == (int) checkcrc.getValue()) { Map<?, ?> map = (Map<?, ?>) JSONValue.parse(new String(parametersBytes, StandardCharsets.UTF_8)); return new CommitLogDescriptor(version, id, parseCompression(map), EncryptionContext.createFromMap(map, encryptionContext)); } return null; }
public static CommitLogDescriptor readHeader(DataInput input, EncryptionContext encryptionContext) throws IOException { CRC32 checkcrc = new CRC32(); int version = input.readInt(); updateChecksumInt(checkcrc, version); long id = input.readLong(); updateChecksumInt(checkcrc, (int) (id & 0xFFFFFFFFL)); updateChecksumInt(checkcrc, (int) (id >>> 32)); int parametersLength = 0; if (version >= VERSION_22) { parametersLength = input.readShort() & 0xFFFF; updateChecksumInt(checkcrc, parametersLength); } // This should always succeed as parametersLength cannot be too long even for a // corrupt segment file. byte[] parametersBytes = new byte[parametersLength]; input.readFully(parametersBytes); checkcrc.update(parametersBytes, 0, parametersBytes.length); int crc = input.readInt(); if (crc == (int) checkcrc.getValue()) { Map<?, ?> map = (Map<?, ?>) JSONValue.parse(new String(parametersBytes, StandardCharsets.UTF_8)); return new CommitLogDescriptor(version, id, parseCompression(map), EncryptionContext.createFromMap(map, encryptionContext)); } return null; }
public static CommitLogDescriptor readHeader(DataInput input, EncryptionContext encryptionContext) throws IOException { CRC32 checkcrc = new CRC32(); int version = input.readInt(); updateChecksumInt(checkcrc, version); long id = input.readLong(); updateChecksumInt(checkcrc, (int) (id & 0xFFFFFFFFL)); updateChecksumInt(checkcrc, (int) (id >>> 32)); int parametersLength = 0; if (version >= VERSION_22) { parametersLength = input.readShort() & 0xFFFF; updateChecksumInt(checkcrc, parametersLength); } // This should always succeed as parametersLength cannot be too long even for a // corrupt segment file. byte[] parametersBytes = new byte[parametersLength]; input.readFully(parametersBytes); checkcrc.update(parametersBytes, 0, parametersBytes.length); int crc = input.readInt(); if (crc == (int) checkcrc.getValue()) { Map<?, ?> map = (Map<?, ?>) JSONValue.parse(new String(parametersBytes, StandardCharsets.UTF_8)); return new CommitLogDescriptor(version, id, parseCompression(map), EncryptionContext.createFromMap(map, encryptionContext)); } return null; }
public static CommitLogDescriptor fromHeader(File file) { try (RandomAccessFile raf = new RandomAccessFile(file, "r")) { assert raf.getFilePointer() == 0; int version = raf.readInt(); long id = raf.readLong(); int crc = raf.readInt(); PureJavaCrc32 checkcrc = new PureJavaCrc32(); checkcrc.updateInt(version); checkcrc.updateInt((int) (id & 0xFFFFFFFFL)); checkcrc.updateInt((int) (id >>> 32)); if (crc == checkcrc.getCrc()) return new CommitLogDescriptor(version, id); return null; } catch (EOFException e) { throw new RuntimeException(e); } catch (IOException e) { throw new FSReadError(e, file); } }
descriptor = new CommitLogDescriptor(id); logFile = new File(DatabaseDescriptor.getCommitLogLocation(), descriptor.fileName()); boolean isCreating = true;
/** * Constructs a new segment file. */ CommitLogSegment(CommitLog commitLog, AbstractCommitLogSegmentManager manager) { this.manager = manager; id = getNextId(); descriptor = new CommitLogDescriptor(id, commitLog.configuration.getCompressorClass(), commitLog.configuration.getEncryptionContext()); logFile = new File(manager.storageDirectory, descriptor.fileName()); try { channel = FileChannel.open(logFile.toPath(), StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE); fd = NativeLibrary.getfd(channel); } catch (IOException e) { throw new FSWriteError(e, logFile); } buffer = createBuffer(commitLog); }
/** * Constructs a new segment file. */ CommitLogSegment(CommitLog commitLog, AbstractCommitLogSegmentManager manager) { this.manager = manager; id = getNextId(); descriptor = new CommitLogDescriptor(id, commitLog.configuration.getCompressorClass(), commitLog.configuration.getEncryptionContext()); logFile = new File(manager.storageDirectory, descriptor.fileName()); try { channel = FileChannel.open(logFile.toPath(), StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE); fd = NativeLibrary.getfd(channel); } catch (IOException e) { throw new FSWriteError(e, logFile); } buffer = createBuffer(commitLog); }
/** * Constructs a new segment file. */ CommitLogSegment(CommitLog commitLog, AbstractCommitLogSegmentManager manager) { this.manager = manager; id = getNextId(); descriptor = new CommitLogDescriptor(id, commitLog.configuration.getCompressorClass(), commitLog.configuration.getEncryptionContext()); logFile = new File(manager.storageDirectory, descriptor.fileName()); try { channel = FileChannel.open(logFile.toPath(), StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE); fd = NativeLibrary.getfd(channel); } catch (IOException e) { throw new FSWriteError(e, logFile); } buffer = createBuffer(commitLog); }