forked from Qortal/qortal
Archive version is now loaded from the version of block 2 in the existing archive, or "defaultArchiveVersion" in settings if not available (default: 1).
This commit is contained in:
parent
abdc265fc6
commit
b6803490b9
@ -738,8 +738,17 @@ public class AdminResource {
|
|||||||
@POST
|
@POST
|
||||||
@Path("/repository/archive/rebuild")
|
@Path("/repository/archive/rebuild")
|
||||||
@Operation(
|
@Operation(
|
||||||
summary = "Rebuild archive.",
|
summary = "Rebuild archive",
|
||||||
description = "Rebuilds archive files, using the serialization version specified via the archiveVersion setting.",
|
description = "Rebuilds archive files, using the specified serialization version",
|
||||||
|
requestBody = @RequestBody(
|
||||||
|
required = true,
|
||||||
|
content = @Content(
|
||||||
|
mediaType = MediaType.TEXT_PLAIN,
|
||||||
|
schema = @Schema(
|
||||||
|
type = "number", example = "2"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
responses = {
|
responses = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
description = "\"true\"",
|
description = "\"true\"",
|
||||||
@ -749,9 +758,14 @@ public class AdminResource {
|
|||||||
)
|
)
|
||||||
@ApiErrors({ApiError.REPOSITORY_ISSUE})
|
@ApiErrors({ApiError.REPOSITORY_ISSUE})
|
||||||
@SecurityRequirement(name = "apiKey")
|
@SecurityRequirement(name = "apiKey")
|
||||||
public String rebuildArchive(@HeaderParam(Security.API_KEY_HEADER) String apiKey) {
|
public String rebuildArchive(@HeaderParam(Security.API_KEY_HEADER) String apiKey, Integer serializationVersion) {
|
||||||
Security.checkApiCallAllowed(request);
|
Security.checkApiCallAllowed(request);
|
||||||
|
|
||||||
|
// Default serialization version to value specified in settings
|
||||||
|
if (serializationVersion == null) {
|
||||||
|
serializationVersion = Settings.getInstance().getDefaultArchiveVersion();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// We don't actually need to lock the blockchain here, but we'll do it anyway so that
|
// We don't actually need to lock the blockchain here, but we'll do it anyway so that
|
||||||
// the node can focus on rebuilding rather than synchronizing / minting.
|
// the node can focus on rebuilding rather than synchronizing / minting.
|
||||||
@ -760,9 +774,7 @@ public class AdminResource {
|
|||||||
blockchainLock.lockInterruptibly();
|
blockchainLock.lockInterruptibly();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int archiveVersion = Settings.getInstance().getArchiveVersion();
|
BlockArchiveRebuilder blockArchiveRebuilder = new BlockArchiveRebuilder(serializationVersion);
|
||||||
|
|
||||||
BlockArchiveRebuilder blockArchiveRebuilder = new BlockArchiveRebuilder(archiveVersion);
|
|
||||||
blockArchiveRebuilder.start();
|
blockArchiveRebuilder.start();
|
||||||
|
|
||||||
return "true";
|
return "true";
|
||||||
|
@ -64,6 +64,19 @@ public class BlockArchiveReader {
|
|||||||
this.fileListCache = Map.copyOf(map);
|
this.fileListCache = Map.copyOf(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer fetchSerializationVersionForHeight(int height) {
|
||||||
|
if (this.fileListCache == null) {
|
||||||
|
this.fetchFileList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Triple<byte[], Integer, Integer> serializedBlock = this.fetchSerializedBlockBytesForHeight(height);
|
||||||
|
if (serializedBlock == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Integer serializationVersion = serializedBlock.getB();
|
||||||
|
return serializationVersion;
|
||||||
|
}
|
||||||
|
|
||||||
public BlockTransformation fetchBlockAtHeight(int height) {
|
public BlockTransformation fetchBlockAtHeight(int height) {
|
||||||
if (this.fileListCache == null) {
|
if (this.fileListCache == null) {
|
||||||
this.fetchFileList();
|
this.fetchFileList();
|
||||||
|
@ -43,7 +43,7 @@ public class BlockArchiveWriter {
|
|||||||
|
|
||||||
private int startHeight;
|
private int startHeight;
|
||||||
private final int endHeight;
|
private final int endHeight;
|
||||||
private final int serializationVersion;
|
private final Integer serializationVersion;
|
||||||
private final Path archivePath;
|
private final Path archivePath;
|
||||||
private final Repository repository;
|
private final Repository repository;
|
||||||
|
|
||||||
@ -65,12 +65,17 @@ public class BlockArchiveWriter {
|
|||||||
* @param endHeight
|
* @param endHeight
|
||||||
* @param repository
|
* @param repository
|
||||||
*/
|
*/
|
||||||
public BlockArchiveWriter(int startHeight, int endHeight, int serializationVersion, Path archivePath, Repository repository) {
|
public BlockArchiveWriter(int startHeight, int endHeight, Integer serializationVersion, Path archivePath, Repository repository) {
|
||||||
this.startHeight = startHeight;
|
this.startHeight = startHeight;
|
||||||
this.endHeight = endHeight;
|
this.endHeight = endHeight;
|
||||||
this.serializationVersion = serializationVersion;
|
|
||||||
this.archivePath = archivePath.toAbsolutePath();
|
this.archivePath = archivePath.toAbsolutePath();
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
|
||||||
|
if (serializationVersion == null) {
|
||||||
|
// When serialization version isn't specified, fetch it from the existing archive
|
||||||
|
serializationVersion = this.findSerializationVersion();
|
||||||
|
}
|
||||||
|
this.serializationVersion = serializationVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,7 +85,18 @@ public class BlockArchiveWriter {
|
|||||||
* @param repository
|
* @param repository
|
||||||
*/
|
*/
|
||||||
public BlockArchiveWriter(int startHeight, int endHeight, Repository repository) {
|
public BlockArchiveWriter(int startHeight, int endHeight, Repository repository) {
|
||||||
this(startHeight, endHeight, Settings.getInstance().getArchiveVersion(), Paths.get(Settings.getInstance().getRepositoryPath(), "archive"), repository);
|
this(startHeight, endHeight, null, Paths.get(Settings.getInstance().getRepositoryPath(), "archive"), repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findSerializationVersion() {
|
||||||
|
// Attempt to fetch the serialization version from the existing archive
|
||||||
|
Integer block2SerializationVersion = BlockArchiveReader.getInstance().fetchSerializationVersionForHeight(2);
|
||||||
|
if (block2SerializationVersion != null) {
|
||||||
|
return block2SerializationVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to version specified in settings
|
||||||
|
return Settings.getInstance().getDefaultArchiveVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxArchiveHeight(Repository repository) throws DataException {
|
public static int getMaxArchiveHeight(Repository repository) throws DataException {
|
||||||
|
@ -179,7 +179,7 @@ public class Settings {
|
|||||||
/** How often to attempt archiving (ms). */
|
/** How often to attempt archiving (ms). */
|
||||||
private long archiveInterval = 7171L; // milliseconds
|
private long archiveInterval = 7171L; // milliseconds
|
||||||
/** Serialization version to use when building an archive */
|
/** Serialization version to use when building an archive */
|
||||||
private int archiveVersion = 1;
|
private int defaultArchiveVersion = 1;
|
||||||
|
|
||||||
|
|
||||||
/** Whether to automatically bootstrap instead of syncing from genesis */
|
/** Whether to automatically bootstrap instead of syncing from genesis */
|
||||||
@ -928,8 +928,8 @@ public class Settings {
|
|||||||
return this.archiveInterval;
|
return this.archiveInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getArchiveVersion() {
|
public int getDefaultArchiveVersion() {
|
||||||
return this.archiveVersion;
|
return this.defaultArchiveVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user