Skip to content

Commit

Permalink
Merge pull request h2database#4057 from andreitokar/issue-4052
Browse files Browse the repository at this point in the history
Allow 0 as a valid chunk id
  • Loading branch information
andreitokar authored May 15, 2024
2 parents 8115ca9 + 1c7edcf commit 80cf2c2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion h2/src/main/org/h2/command/CommandContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public CommandContainer(SessionLocal session, String sql, Prepared prepared) {
@Override
public ArrayList<? extends ParameterInterface> getParameters() {
ArrayList<Parameter> parameters = prepared.getParameters();
if (parameters.size() > 0 && prepared.isWithParamValues()) {
if (!parameters.isEmpty() && prepared.isWithParamValues()) {
parameters = new ArrayList<>();
}
return parameters;
Expand Down
4 changes: 2 additions & 2 deletions h2/src/main/org/h2/mvstore/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public abstract class Chunk<C extends Chunk<C>> {
}

Chunk(Map<String, String> map, boolean full) {
this(DataUtils.readHexInt(map, ATTR_CHUNK, 0));
this(DataUtils.readHexInt(map, ATTR_CHUNK, -1));
block = DataUtils.readHexLong(map, ATTR_BLOCK, 0);
len = DataUtils.readHexInt(map, ATTR_LEN, 0);
version = DataUtils.readHexLong(map, ATTR_VERSION, id);
Expand Down Expand Up @@ -206,7 +206,7 @@ public abstract class Chunk<C extends Chunk<C>> {

Chunk(int id) {
this.id = id;
if (id <= 0) {
if (id < 0 || id > MAX_ID) {
throw DataUtils.newMVStoreException(
DataUtils.ERROR_FILE_CORRUPT, "Invalid chunk id {0}", id);
}
Expand Down
4 changes: 2 additions & 2 deletions h2/src/main/org/h2/mvstore/RandomAccessStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ protected void readStoreHeader(boolean recoveryMode) {
// no (valid) next
break;
}
SFChunk test = readChunkHeaderAndFooter(newest.next, newest.id + 1);
SFChunk test = readChunkHeaderAndFooter(newest.next, (newest.id + 1) & Chunk.MAX_ID);
if (test == null || test.version <= newest.version) {
break;
}
Expand Down Expand Up @@ -386,7 +386,7 @@ private boolean shouldWriteStoreHeader(SFChunk c, boolean storeAtEndOfFile) {
if (chunk == null) {
writeStoreHeader = true;
} else if (chunk.next != c.block) {
// the last prediction did not matched
// the last prediction did not match
writeStoreHeader = true;
} else {
long headerVersion = DataUtils.readHexLong(storeHeader, HDR_VERSION, 0);
Expand Down

0 comments on commit 80cf2c2

Please sign in to comment.