Skip to content

Commit

Permalink
Try with old cache version
Browse files Browse the repository at this point in the history
  • Loading branch information
rickb80 committed Jul 29, 2023
1 parent a07876d commit 725f721
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/config/definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//#define LOG_TIME_STATISTICS_STATEDB_REMOTE // If defined, generates remote statedb statistics
//#define LOG_TIME_STATISTICS_STATEDB // If defined, generates statedb statistics
#define LOG_TIME_STATISTICS_MAIN_EXECUTOR
//#define TIME_METRIC_TABLE
#define TIME_METRIC_TABLE
//#define LOG_TXS
//#define LOG_SERVICE
#define LOG_SERVICE_EXECUTOR_INPUT
Expand Down Expand Up @@ -70,6 +70,6 @@
//#define HASHDB_LOCK // If defined, the HashDB class will use a lock in all its methods, i.e. they will be serialized
//#define DATABASE_COMMIT // If defined, the Database class can be configured to autocommit, or explicitly commit(); used for testing only
#define DATABASE_USE_CACHE // If defined, the Database class uses a cache
#define DATABASE_USE_ASSOCIATIVE_CACHE // If defined, the Database class uses an associative cache
//#define DATABASE_USE_ASSOCIATIVE_CACHE // If defined, the Database class uses an associative cache

#endif
27 changes: 4 additions & 23 deletions src/hashdb/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1692,13 +1692,10 @@ void Database::printTree(const string &root, string prefix)
}
string key = root;
vector<Goldilocks::Element> value;
#ifdef DATABASE_USE_ASSOCIATIVE_CACHE
Goldilocks::Element vKey[4];
string2fea(fr, key, vKey);
string2fea(fr, key, vKey);
read(vKey,value, NULL);
#else
read(key, value, NULL);
#endif

if (value.size() != 12)
{
zklog.error("Database::printTree() found value.size()=" + to_string(value.size()));
Expand Down Expand Up @@ -1737,12 +1734,8 @@ void Database::printTree(const string &root, string prefix)
string hashValue = fea2string(fr, value[4], value[5], value[6], value[7]);
zklog.info(prefix + "hashValue=" + hashValue);
vector<Goldilocks::Element> leafValue;
#ifdef DATABASE_USE_ASSOCIATIVE_CACHE
Goldilocks::Element vKey[4]={value[4],value[5],value[6],value[7]};
read(vKey, leafValue, NULL);
#else
read(hashValue, leafValue, NULL);
#endif
if (leafValue.size() == 12)
{
if (!fr.equal(leafValue[8], fr.zero()))
Expand Down Expand Up @@ -2011,12 +2004,8 @@ void loadDb2MemCache(const Config &config)
HashDB * pHashDB = (HashDB *)hashDBSingleton.get();

vector<Goldilocks::Element> dbValue;

#ifdef DATABASE_USE_ASSOCIATIVE_CACHE
zkresult zkr = pHashDB->db.read(Database::dbStateRootvKey, dbValue, NULL, true);
#else
zkresult zkr = pHashDB->db.read(Database::dbStateRootKey, dbValue, NULL, true);
#endif

if (zkr == ZKR_DB_KEY_NOT_FOUND)
{
zklog.warning("loadDb2MemCache() dbStateRootKey=" + Database::dbStateRootKey + " not found in database; normal only if database is empty");
Expand Down Expand Up @@ -2084,13 +2073,10 @@ void loadDb2MemCache(const Config &config)

hash = treeMapIterator->second[i];
dbValue.clear();
#ifdef DATABASE_USE_ASSOCIATIVE_CACHE
Goldilocks::Element vhash[4];
string2fea(fr, hash, vhash);
zkresult zkr = pHashDB->db.read(vhash, dbValue, NULL, true);
#else
zkresult zkr = pHashDB->db.read(hash, dbValue, NULL, true);
#endif

if (zkr != ZKR_SUCCESS)
{
zklog.error("loadDb2MemCache() failed calling db.read(" + hash + ") result=" + zkresult2string(zkr));
Expand Down Expand Up @@ -2140,13 +2126,8 @@ void loadDb2MemCache(const Config &config)
//zklog.info("loadDb2MemCache() level=" + to_string(level) + " found value rightHash=" + rightHash);
dbValue.clear();

#ifdef DATABASE_USE_ASSOCIATIVE_CACHE
Goldilocks::Element vRightHash[4]={dbValue[4], dbValue[5], dbValue[6], dbValue[7]};
zkresult zkr = pHashDB->db.read(vRightHash, dbValue, NULL, true);
#else

zkresult zkr = pHashDB->db.read(rightHash, dbValue, NULL, true);
#endif
if (zkr != ZKR_SUCCESS)
{
zklog.error("loadDb2MemCache() failed calling db.read(" + rightHash + ") result=" + zkresult2string(zkr));
Expand Down
2 changes: 1 addition & 1 deletion test/hashdb/database_cache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ uint64_t DatabaseCacheTest (void)
#endif
Goldilocks fr;
mpz_class keyScalar;
Goldilocks::Element key[4];

string keyString;
vector<Goldilocks::Element> value;
Expand All @@ -37,6 +36,7 @@ uint64_t DatabaseCacheTest (void)
#ifndef DATABASE_USE_ASSOCIATIVE_CACHE
Database::dbMTCache.add(keyString, value, update);
#else
Goldilocks::Element key[4];
scalar2fea(fr, keyScalar, key);
Database::dbMTCache.addKeyValue(key, value,update);
#endif
Expand Down

0 comments on commit 725f721

Please sign in to comment.