Skip to content

Commit

Permalink
Rename unique assocaitive cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rickb80 committed Jul 28, 2023
1 parent 4cdc014 commit 6e4dbd2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/hashdb/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// This will be used to store DB records in memory and it will be shared for all the instances of Database class
// DatabaseCacheMT and DatabaseCacheProgram classes are thread-safe
#ifdef DATABASE_USE_ASSOCIATIVE_CACHE
DatabaseMTAssociativeCache2 Database::dbMTCache;
DatabaseMTAssociativeCache Database::dbMTCache;
//DatabaseMTAssociativeCache Database::dbMTCache;

#else
Expand Down
4 changes: 2 additions & 2 deletions src/hashdb/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "zkassert.hpp"
#include "tree_position.hpp"
#include "multi_write.hpp"
#include "database_associative_cache_2.hpp"
#include "database_associative_cache.hpp"

using namespace std;

Expand Down Expand Up @@ -71,7 +71,7 @@ class Database
#ifdef DATABASE_USE_CACHE
// Cache static instances
#ifdef DATABASE_USE_ASSOCIATIVE_CACHE
static DatabaseMTAssociativeCache2 dbMTCache;
static DatabaseMTAssociativeCache dbMTCache;
//static DatabaseMTAssociativeCache dbMTCache;

#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@



DatabaseMTAssociativeCache2::DatabaseMTAssociativeCache2()
DatabaseMTAssociativeCache::DatabaseMTAssociativeCache()
{
nKeyBits = 0;
indicesSize = 0;
Expand All @@ -24,12 +24,12 @@ DatabaseMTAssociativeCache2::DatabaseMTAssociativeCache2()
name = "";
};

DatabaseMTAssociativeCache2::DatabaseMTAssociativeCache2(int nKeyBits_, int cacheSize_, string name_)
DatabaseMTAssociativeCache::DatabaseMTAssociativeCache(int nKeyBits_, int cacheSize_, string name_)
{
postConstruct(nKeyBits_, cacheSize_, name_);
};

DatabaseMTAssociativeCache2::~DatabaseMTAssociativeCache2()
DatabaseMTAssociativeCache::~DatabaseMTAssociativeCache()
{
if (indices != NULL)
delete[] indices;
Expand All @@ -41,12 +41,12 @@ DatabaseMTAssociativeCache2::~DatabaseMTAssociativeCache2()
delete[] isLeaf;
};

void DatabaseMTAssociativeCache2::postConstruct(int nKeyBits_, int cacheSize_, string name_)
void DatabaseMTAssociativeCache::postConstruct(int nKeyBits_, int cacheSize_, string name_)
{
nKeyBits = nKeyBits_;
if (nKeyBits_ > 64)
{
zklog.error("DatabaseMTAssociativeCache2::DatabaseMTAssociativeCache2() nKeyBits_ > 64");
zklog.error("DatabaseMTAssociativeCache::DatabaseMTAssociativeCache() nKeyBits_ > 64");
exit(1);
}
indicesSize = 1 << nKeyBits;
Expand All @@ -70,15 +70,15 @@ void DatabaseMTAssociativeCache2::postConstruct(int nKeyBits_, int cacheSize_, s
}
};

void DatabaseMTAssociativeCache2::addKeyValue(Goldilocks::Element (&key)[4], const vector<Goldilocks::Element> &value, bool update)
void DatabaseMTAssociativeCache::addKeyValue(Goldilocks::Element (&key)[4], const vector<Goldilocks::Element> &value, bool update)
{
//
// Statistics
//
attempts++; // must be atomic operation!! makes it sence? not really
if (attempts << 44 == 0)
{
zklog.info("DatabaseMTAssociativeCache2::addKeyValue() name=" + name + " indicesSize=" + to_string(indicesSize) + " cacheSize=" + to_string(cacheSize) + " attempts=" + to_string(attempts) + " hits=" + to_string(hits) + " hit ratio=" + to_string(double(hits) * 100.0 / double(zkmax(attempts, 1))) + "%");
zklog.info("DatabaseMTAssociativeCache::addKeyValue() name=" + name + " indicesSize=" + to_string(indicesSize) + " cacheSize=" + to_string(cacheSize) + " attempts=" + to_string(attempts) + " hits=" + to_string(hits) + " hit ratio=" + to_string(double(hits) * 100.0 / double(zkmax(attempts, 1))) + "%");
}

//
Expand Down Expand Up @@ -178,7 +178,7 @@ void DatabaseMTAssociativeCache2::addKeyValue(Goldilocks::Element (&key)[4], con
forcedInsertion(cacheIndex, iters);
}

void DatabaseMTAssociativeCache2::forcedInsertion(uint32_t index, int &iters)
void DatabaseMTAssociativeCache::forcedInsertion(uint32_t index, int &iters)
{
//
// avoid infinite loop
Expand Down Expand Up @@ -220,7 +220,7 @@ void DatabaseMTAssociativeCache2::forcedInsertion(uint32_t index, int &iters)
forcedInsertion(minCacheIndex, iters);
}

bool DatabaseMTAssociativeCache2::findKey(Goldilocks::Element (&key)[4], vector<Goldilocks::Element> &value)
bool DatabaseMTAssociativeCache::findKey(Goldilocks::Element (&key)[4], vector<Goldilocks::Element> &value)
{
for (int i = 0; i < 4; i++)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DATABASE_ASSOCIATIVE_CACHE_2_HPP
#define DATABASE_ASSOCIATIVE_CACHE_2_HPP
#ifndef DATABASE_ASSOCIATIVE_CACHE_HPP
#define DATABASE_ASSOCIATIVE_CACHE_HPP
#include <vector>
#include "goldilocks_base_field.hpp"
#include <nlohmann/json.hpp>
Expand All @@ -9,7 +9,7 @@

using namespace std;
using json = nlohmann::json;
class DatabaseMTAssociativeCache2
class DatabaseMTAssociativeCache
{
private:
recursive_mutex mlock;
Expand All @@ -32,9 +32,9 @@ class DatabaseMTAssociativeCache2

public:

DatabaseMTAssociativeCache2();
DatabaseMTAssociativeCache2(int nKeyBits_, int cacheSize_, string name_);
~DatabaseMTAssociativeCache2();
DatabaseMTAssociativeCache();
DatabaseMTAssociativeCache(int nKeyBits_, int cacheSize_, string name_);
~DatabaseMTAssociativeCache();

void postConstruct(int nKeyBits_, int cacheSize_, string name_);
void addKeyValue(Goldilocks::Element (&key)[4], const vector<Goldilocks::Element> &value, bool update);
Expand Down

0 comments on commit 6e4dbd2

Please sign in to comment.