mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +00:00
Added support for minimum db.compact() threshold
This commit is contained in:
@@ -3468,6 +3468,7 @@ void MeshServer_Connect(MeshAgentHostContainer *agent)
|
|||||||
|
|
||||||
util_random(sizeof(int), (char*)&timeout);
|
util_random(sizeof(int), (char*)&timeout);
|
||||||
gRemoteMouseRenderDefault = ILibSimpleDataStore_Get(agent->masterDb, "remoteMouseRender", NULL, 0);
|
gRemoteMouseRenderDefault = ILibSimpleDataStore_Get(agent->masterDb, "remoteMouseRender", NULL, 0);
|
||||||
|
ILibSimpleDataStore_ConfigCompact(agent->masterDb, ILibSimpleDataStore_GetInt(agent->masterDb, "compactDirtyMinimum", 0));
|
||||||
agent->disableUpdate = ILibSimpleDataStore_Get(agent->masterDb, "disableUpdate", NULL, 0);
|
agent->disableUpdate = ILibSimpleDataStore_Get(agent->masterDb, "disableUpdate", NULL, 0);
|
||||||
agent->forceUpdate = ILibSimpleDataStore_Get(agent->masterDb, "forceUpdate", NULL, 0);
|
agent->forceUpdate = ILibSimpleDataStore_Get(agent->masterDb, "forceUpdate", NULL, 0);
|
||||||
agent->logUpdate = ILibSimpleDataStore_Get(agent->masterDb, "logUpdate", NULL, 0);
|
agent->logUpdate = ILibSimpleDataStore_Get(agent->masterDb, "logUpdate", NULL, 0);
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ char* MeshAgent_MakeAbsolutePath(char *basePath, char *localPath);
|
|||||||
*
|
*
|
||||||
AgentCapabilities: Integer Mask, specifying supported Agent Capabilities
|
AgentCapabilities: Integer Mask, specifying supported Agent Capabilities
|
||||||
agentName If set, this will be sent to the server instead of the hostname
|
agentName If set, this will be sent to the server instead of the hostname
|
||||||
|
compactDirtyMinimum Minimum dirty bytes threshold for db.compact() operation
|
||||||
controlChannelDebug: If set, will log/display controlChannel messages (Except for JSON messages)
|
controlChannelDebug: If set, will log/display controlChannel messages (Except for JSON messages)
|
||||||
controlChannelIdleTimeout: Integer value specifying the idle timeout in seconds, to send Ping/Pong to server, to keep connection alive
|
controlChannelIdleTimeout: Integer value specifying the idle timeout in seconds, to send Ping/Pong to server, to keep connection alive
|
||||||
coreDumpEnabled: If set, a dump file will be written when the agent crashes
|
coreDumpEnabled: If set, a dump file will be written when the agent crashes
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ typedef struct ILibSimpleDataStore_Root
|
|||||||
ILibHashtable keyTable; // keys --> ILibSimpleDataStore_TableEntry
|
ILibHashtable keyTable; // keys --> ILibSimpleDataStore_TableEntry
|
||||||
ILibHashtable cacheTable;
|
ILibHashtable cacheTable;
|
||||||
uint64_t fileSize;
|
uint64_t fileSize;
|
||||||
|
uint64_t dirtySize;
|
||||||
|
uint64_t minimumDirtySize;
|
||||||
int error;
|
int error;
|
||||||
} ILibSimpleDataStore_Root;
|
} ILibSimpleDataStore_Root;
|
||||||
|
|
||||||
@@ -388,7 +390,17 @@ void ILibSimpleDataStore_RebuildKeyTable(ILibSimpleDataStore_Root *root)
|
|||||||
if (node->valueLength > 0)
|
if (node->valueLength > 0)
|
||||||
{
|
{
|
||||||
// If the value is not empty, we need to create/overwrite this value in memory
|
// If the value is not empty, we need to create/overwrite this value in memory
|
||||||
if (entry == NULL) { ++count; entry = (ILibSimpleDataStore_TableEntry*)ILibMemory_Allocate(sizeof(ILibSimpleDataStore_TableEntry), 0, NULL, NULL); }
|
if (entry == NULL)
|
||||||
|
{
|
||||||
|
// Create new entry in table
|
||||||
|
++count;
|
||||||
|
entry = (ILibSimpleDataStore_TableEntry*)ILibMemory_Allocate(sizeof(ILibSimpleDataStore_TableEntry), 0, NULL, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Entry already exists in table
|
||||||
|
root->dirtySize += entry->valueLength;
|
||||||
|
}
|
||||||
memcpy_s(entry->valueHash, sizeof(entry->valueHash), node->hash, SHA384HASHSIZE);
|
memcpy_s(entry->valueHash, sizeof(entry->valueHash), node->hash, SHA384HASHSIZE);
|
||||||
entry->valueLength = node->valueLength;
|
entry->valueLength = node->valueLength;
|
||||||
entry->valueOffset = ILibSimpleDataStore_RecordHeader_ValueOffset(node);
|
entry->valueOffset = ILibSimpleDataStore_RecordHeader_ValueOffset(node);
|
||||||
@@ -397,6 +409,7 @@ void ILibSimpleDataStore_RebuildKeyTable(ILibSimpleDataStore_Root *root)
|
|||||||
else if (entry != NULL)
|
else if (entry != NULL)
|
||||||
{
|
{
|
||||||
// If value is empty, remove the in-memory entry.
|
// If value is empty, remove the in-memory entry.
|
||||||
|
root->dirtySize += entry->valueLength;
|
||||||
--count;
|
--count;
|
||||||
ILibHashtable_Remove(root->keyTable, NULL, node->key, node->keyLen);
|
ILibHashtable_Remove(root->keyTable, NULL, node->key, node->keyLen);
|
||||||
free(entry);
|
free(entry);
|
||||||
@@ -599,10 +612,14 @@ __EXPORT_TYPE int ILibSimpleDataStore_PutEx(ILibSimpleDataStore dataStore, char*
|
|||||||
ILibSimpleDataStore_SHA384(value, valueLen, hash); // Hash the value
|
ILibSimpleDataStore_SHA384(value, valueLen, hash); // Hash the value
|
||||||
|
|
||||||
// Create a new record for the key and value
|
// Create a new record for the key and value
|
||||||
if (entry == NULL) {
|
if (entry == NULL)
|
||||||
entry = (ILibSimpleDataStore_TableEntry*)ILibMemory_Allocate(sizeof(ILibSimpleDataStore_TableEntry), 0, NULL, NULL); }
|
{
|
||||||
else {
|
entry = (ILibSimpleDataStore_TableEntry*)ILibMemory_Allocate(sizeof(ILibSimpleDataStore_TableEntry), 0, NULL, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (memcmp(entry->valueHash, hash, SHA384HASHSIZE) == 0) { return 0; }
|
if (memcmp(entry->valueHash, hash, SHA384HASHSIZE) == 0) { return 0; }
|
||||||
|
root->dirtySize += entry->valueLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy_s(entry->valueHash, sizeof(entry->valueHash), hash, SHA384HASHSIZE);
|
memcpy_s(entry->valueHash, sizeof(entry->valueHash), hash, SHA384HASHSIZE);
|
||||||
@@ -614,6 +631,13 @@ __EXPORT_TYPE int ILibSimpleDataStore_PutEx(ILibSimpleDataStore dataStore, char*
|
|||||||
return ILibHashtable_Put(root->keyTable, NULL, key, keyLen, entry) == NULL ? 0 : 1;
|
return ILibHashtable_Put(root->keyTable, NULL, key, keyLen, entry) == NULL ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__EXPORT_TYPE int ILibSimpleDataStore_GetInt(ILibSimpleDataStore dataStore, char* key, int defaultValue)
|
||||||
|
{
|
||||||
|
int bufLen = ILibSimpleDataStore_Get(dataStore, key, ILibScratchPad, sizeof(ILibScratchPad));
|
||||||
|
if (bufLen == 0 || bufLen > sizeof(ILibScratchPad)) { return(defaultValue); }
|
||||||
|
return(atoi(ILibScratchPad));
|
||||||
|
}
|
||||||
|
|
||||||
// Get a value from the data store given a key
|
// Get a value from the data store given a key
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char *buffer, int bufferLen)
|
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char *buffer, int bufferLen)
|
||||||
{
|
{
|
||||||
@@ -776,7 +800,11 @@ __EXPORT_TYPE void ILibSimpleDataStore_EnumerateKeys(ILibSimpleDataStore dataSto
|
|||||||
|
|
||||||
if (handler != NULL) { ILibHashtable_Enumerate(root->keyTable, ILibSimpleDataStore_EnumerateKeysSink, users); }
|
if (handler != NULL) { ILibHashtable_Enumerate(root->keyTable, ILibSimpleDataStore_EnumerateKeysSink, users); }
|
||||||
}
|
}
|
||||||
|
__EXPORT_TYPE void ILibSimpleDataStore_ConfigCompact(ILibSimpleDataStore dataStore, uint64_t minimumDirtySize)
|
||||||
|
{
|
||||||
|
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||||
|
root->minimumDirtySize = minimumDirtySize;
|
||||||
|
}
|
||||||
// Compact the data store
|
// Compact the data store
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_Compact(ILibSimpleDataStore dataStore)
|
__EXPORT_TYPE int ILibSimpleDataStore_Compact(ILibSimpleDataStore dataStore)
|
||||||
{
|
{
|
||||||
@@ -786,7 +814,7 @@ __EXPORT_TYPE int ILibSimpleDataStore_Compact(ILibSimpleDataStore dataStore)
|
|||||||
void* state[2];
|
void* state[2];
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
|
|
||||||
if (root == NULL) return 1; // Error
|
if (root == NULL || root->dirtySize < root->minimumDirtySize) return 1; // Error
|
||||||
tmp = ILibString_Cat(root->filePath, -1, ".tmp", -1); // Create the name of the temporary data store
|
tmp = ILibString_Cat(root->filePath, -1, ".tmp", -1); // Create the name of the temporary data store
|
||||||
|
|
||||||
// Start by opening a temporary .tmp file. Will be used to write the compacted data store.
|
// Start by opening a temporary .tmp file. Will be used to write the compacted data store.
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ __EXPORT_TYPE void ILibSimpleDataStore_Close(ILibSimpleDataStore dataStore);
|
|||||||
__EXPORT_TYPE void ILibSimpleDataStore_Cached(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen);
|
__EXPORT_TYPE void ILibSimpleDataStore_Cached(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen);
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSON(ILibSimpleDataStore dataStore, char *buffer, int bufferLen);
|
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSON(ILibSimpleDataStore dataStore, char *buffer, int bufferLen);
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSONEx(ILibSimpleDataStore dataStore, char *buffer, int bufferLen);
|
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSONEx(ILibSimpleDataStore dataStore, char *buffer, int bufferLen);
|
||||||
|
__EXPORT_TYPE void ILibSimpleDataStore_ConfigCompact(ILibSimpleDataStore dataStore, uint64_t minimumDirtySize);
|
||||||
|
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_PutEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen);
|
__EXPORT_TYPE int ILibSimpleDataStore_PutEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen);
|
||||||
#define ILibSimpleDataStore_Put(dataStore, key, value) ILibSimpleDataStore_PutEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), value, (int)strnlen_s(value, ILibSimpleDataStore_MaxUnspecifiedValueLen))
|
#define ILibSimpleDataStore_Put(dataStore, key, value) ILibSimpleDataStore_PutEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), value, (int)strnlen_s(value, ILibSimpleDataStore_MaxUnspecifiedValueLen))
|
||||||
@@ -61,6 +62,7 @@ __EXPORT_TYPE int ILibSimpleDataStore_PutEx(ILibSimpleDataStore dataStore, char*
|
|||||||
// Get a value from the datastore of given a key.
|
// Get a value from the datastore of given a key.
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char* buffer, int bufferLen);
|
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char* buffer, int bufferLen);
|
||||||
#define ILibSimpleDataStore_Get(dataStore, key, buffer, bufferLen) ILibSimpleDataStore_GetEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), buffer, bufferLen)
|
#define ILibSimpleDataStore_Get(dataStore, key, buffer, bufferLen) ILibSimpleDataStore_GetEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), buffer, bufferLen)
|
||||||
|
__EXPORT_TYPE int ILibSimpleDataStore_GetInt(ILibSimpleDataStore dataStore, char* key, int defaultValue);
|
||||||
|
|
||||||
// Get the SHA256 hash value from the datastore for a given a key.
|
// Get the SHA256 hash value from the datastore for a given a key.
|
||||||
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, int keyLen);
|
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, int keyLen);
|
||||||
|
|||||||
Reference in New Issue
Block a user