-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some issues which caused some log to be missing when calling the eth_getLogs method - Setting up a cache version - Add a check integrity of the cache - Fix a lock issue Signed-off-by: Karim TAAM <[email protected]>
- Loading branch information
Showing
16 changed files
with
411 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...pi/src/main/java/org/hyperledger/besu/ethereum/api/query/cache/LogBloomCacheMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.api.query.cache; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class LogBloomCacheMetadata { | ||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
public static final int DEFAULT_VERSION = 1; | ||
|
||
private static final String METADATA_FILENAME = "CACHE_METADATA.json"; | ||
private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
private final int version; | ||
|
||
@JsonCreator | ||
public LogBloomCacheMetadata(@JsonProperty("version") final int version) { | ||
this.version = version; | ||
} | ||
|
||
public int getVersion() { | ||
return version; | ||
} | ||
|
||
public static LogBloomCacheMetadata lookUpFrom(final Path dataDir) throws IOException { | ||
LOG.info("Lookup cache metadata file in data directory: {}", dataDir.toString()); | ||
return resolveDatabaseMetadata(getDefaultMetadataFile(dataDir)); | ||
} | ||
|
||
public void writeToDirectory(final Path dataDir) throws IOException { | ||
MAPPER.writeValue(getDefaultMetadataFile(dataDir), this); | ||
} | ||
|
||
private static File getDefaultMetadataFile(final Path dataDir) { | ||
return dataDir.resolve(METADATA_FILENAME).toFile(); | ||
} | ||
|
||
private static LogBloomCacheMetadata resolveDatabaseMetadata(final File metadataFile) | ||
throws IOException { | ||
LogBloomCacheMetadata databaseMetadata; | ||
try { | ||
databaseMetadata = MAPPER.readValue(metadataFile, LogBloomCacheMetadata.class); | ||
} catch (FileNotFoundException fnfe) { | ||
databaseMetadata = new LogBloomCacheMetadata(0); | ||
} catch (JsonProcessingException jpe) { | ||
throw new IllegalStateException( | ||
String.format("Invalid metadata file %s", metadataFile.getAbsolutePath()), jpe); | ||
} | ||
return databaseMetadata; | ||
} | ||
} |
Oops, something went wrong.