use of org.projectnessie.versioned.persist.adapter.RefLog in project nessie by projectnessie.
the class TxDatabaseAdapter method doFetchPageFromRefLog.
@Override
protected List<RefLog> doFetchPageFromRefLog(ConnectionWrapper connection, List<Hash> hashes) {
String sql = sqlForManyPlaceholders(SqlStatements.SELECT_REF_LOG_MANY, hashes.size());
try (PreparedStatement ps = connection.conn().prepareStatement(sql)) {
ps.setString(1, config.getRepositoryId());
for (int i = 0; i < hashes.size(); i++) {
ps.setString(2 + i, hashes.get(i).asString());
}
Map<Hash, RefLog> result = new HashMap<>(hashes.size() * 2);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
RefLog entry = protoToRefLog(rs.getBytes(1));
result.put(Objects.requireNonNull(entry).getRefLogId(), entry);
}
}
return hashes.stream().map(result::get).collect(Collectors.toList());
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.projectnessie.versioned.persist.adapter.RefLog in project nessie by projectnessie.
the class NonTransactionalDatabaseAdapter method writeRefLogEntry.
protected RefLogEntry writeRefLogEntry(NonTransactionalOperationContext ctx, GlobalStatePointer pointer, String refName, RefType refType, Hash commitHash, Operation operation, long timeInMicros, List<Hash> sourceHashes) throws ReferenceConflictException {
Hash parentHash = Hash.of(pointer.getRefLogId());
Hash currentRefLogId = randomHash();
Stream<ByteString> newParents;
if (pointer.getRefLogParentsInclHeadCount() == 0 || !pointer.getRefLogId().equals(pointer.getRefLogParentsInclHead(0))) {
// Before Nessie 0.21.0
newParents = Stream.of(parentHash.asBytes());
RefLog currentEntry = fetchFromRefLog(ctx, parentHash);
if (currentEntry != null) {
newParents = Stream.concat(newParents, currentEntry.getParents().stream().limit(config.getParentsPerRefLogEntry() - 1).map(Hash::asBytes));
}
} else {
// Since Nessie 0.21.0
newParents = pointer.getRefLogParentsInclHeadList().stream().limit(config.getParentsPerRefLogEntry());
}
RefLogEntry.Builder entry = RefLogEntry.newBuilder().setRefLogId(currentRefLogId.asBytes()).setRefName(ByteString.copyFromUtf8(refName)).setRefType(refType).setCommitHash(commitHash.asBytes()).setOperationTime(timeInMicros).setOperation(operation);
sourceHashes.forEach(hash -> entry.addSourceHashes(hash.asBytes()));
newParents.forEach(entry::addParents);
RefLogEntry refLogEntry = entry.build();
writeRefLog(ctx, refLogEntry);
return refLogEntry;
}
use of org.projectnessie.versioned.persist.adapter.RefLog in project nessie by projectnessie.
the class TxDatabaseAdapter method writeRefLogEntry.
private RefLogEntry writeRefLogEntry(ConnectionWrapper connection, NamedRef ref, RefLogHead refLogHead, Hash commitHash, Operation operation, long timeInMicros, List<Hash> sourceHashes) throws ReferenceConflictException {
ByteString newId = randomHash().asBytes();
// Before Nessie 0.21.0: only the "head" of the ref-log is maintained, so Nessie has to read
// the head entry of the ref-log to get the IDs of all the previous parents to fill the parents
// in the new ref-log-entry.
//
// Since Nessie 0.21.0: the "head" for the ref-log and PLUS the parents of if are persisted,
// so Nessie no longer need to read the head entries from the ref-log.
//
// The check of the first entry is there to ensure backwards compatibility and also
// rolling-upgrades work.
Stream<ByteString> newParents;
if (refLogHead.getRefLogParentsInclHead().isEmpty() || !refLogHead.getRefLogParentsInclHead().get(0).equals(refLogHead.getRefLogHead())) {
// Before Nessie 0.21.0
newParents = Stream.of(refLogHead.getRefLogHead().asBytes());
RefLog parentEntry = fetchFromRefLog(connection, refLogHead.getRefLogHead());
if (parentEntry != null) {
newParents = Stream.concat(newParents, parentEntry.getParents().stream().limit(config.getParentsPerRefLogEntry() - 1).map(Hash::asBytes));
}
} else {
// Since Nessie 0.21.0
newParents = refLogHead.getRefLogParentsInclHead().stream().map(Hash::asBytes);
}
RefLogEntry.RefType refType = ref instanceof TagName ? RefLogEntry.RefType.Tag : RefLogEntry.RefType.Branch;
RefLogEntry.Builder entry = RefLogEntry.newBuilder().setRefLogId(newId).setRefName(ByteString.copyFromUtf8(ref.getName())).setRefType(refType).setCommitHash(commitHash.asBytes()).setOperationTime(timeInMicros).setOperation(operation);
sourceHashes.forEach(hash -> entry.addSourceHashes(hash.asBytes()));
newParents.forEach(entry::addParents);
RefLogEntry refLogEntry = entry.build();
writeRefLog(connection, refLogEntry);
return refLogEntry;
}
Aggregations