Skip to content

Commit

Permalink
Fix making an insert instead of update request when writing disk params
Browse files Browse the repository at this point in the history
  • Loading branch information
joelarmstrong committed Jul 6, 2017
1 parent 08694b3 commit cf25d3e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
16 changes: 11 additions & 5 deletions api/impl/cactusDisk.c
Expand Up @@ -606,17 +606,23 @@ void cactusDisk_addUpdateRequest(CactusDisk *cactusDisk, Flower *flower) {
free(compressed);
}

void cactusDisk_forceParameterUpdate(CactusDisk *cactusDisk) {
void cactusDisk_forceParameterUpdate(CactusDisk *cactusDisk, bool keyAlreadyExists) {
int64_t recordSize;
void *cactusDiskParameters =
binaryRepresentation_makeBinaryRepresentation(cactusDisk,
(void (*)(void *, void (*)(const void * ptr, size_t size, size_t count))) cactusDisk_writeBinaryRepresentation,
&recordSize);
//Compression
cactusDiskParameters = compress(cactusDiskParameters, &recordSize);
stList_append(cactusDisk->updateRequests,
stKVDatabaseBulkRequest_constructUpdateRequest(CACTUS_DISK_PARAMETER_KEY, cactusDiskParameters,
recordSize));
if (keyAlreadyExists) {
stList_append(cactusDisk->updateRequests,
stKVDatabaseBulkRequest_constructUpdateRequest(CACTUS_DISK_PARAMETER_KEY, cactusDiskParameters,
recordSize));
} else {
stList_append(cactusDisk->updateRequests,
stKVDatabaseBulkRequest_constructInsertRequest(CACTUS_DISK_PARAMETER_KEY, cactusDiskParameters,
recordSize));
}
free(cactusDiskParameters);
}

Expand Down Expand Up @@ -675,7 +681,7 @@ void cactusDisk_write(CactusDisk *cactusDisk) {
st_logDebug("Got the sequences we are going to add to the database.\n");

if (!containsRecord(cactusDisk, CACTUS_DISK_PARAMETER_KEY)) { //We only write the parameters once.
cactusDisk_forceParameterUpdate(cactusDisk);
cactusDisk_forceParameterUpdate(cactusDisk, false);
}

st_logDebug("Checked if need to write the initial parameters\n");
Expand Down
6 changes: 4 additions & 2 deletions api/inc/cactusDisk.h
Expand Up @@ -103,8 +103,10 @@ EventTree *cactusDisk_getEventTree(CactusDisk *cactusDisk);

/*
* Forces an update of the cactusDisk base parameters (event tree,
* etc.) on the next write.
* etc.) on the next write. Set keyAlreadyExists to true if this is an
* update of the existing parameters, false if the parameters are
* being inserted for the first time.
*/
void cactusDisk_forceParameterUpdate(CactusDisk *cactusDisk);
void cactusDisk_forceParameterUpdate(CactusDisk *cactusDisk, bool keyAlreadyExists);

#endif
2 changes: 1 addition & 1 deletion phylogeny/cactus_phylogeny.c
Expand Up @@ -877,7 +877,7 @@ int main(int argc, char *argv[]) {
///////////////////////////////////////////////////////////////////////////

startTime = time(NULL);
cactusDisk_forceParameterUpdate(cactusDisk);
cactusDisk_forceParameterUpdate(cactusDisk, true);
cactusDisk_write(cactusDisk);
st_logInfo("Updated the flower on disk in: %" PRIi64 " seconds\n", time(NULL)
- startTime);
Expand Down

0 comments on commit cf25d3e

Please sign in to comment.