Last active
July 9, 2018 11:07
-
-
Save kirilltitov/97a6bfc8cdd8a5a08b60bea8536c507c to your computer and use it in GitHub Desktop.
FoundationDB memory leak test
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
#define FDB_API_VERSION 520 | |
#include "foundationdb/fdb_c.h" | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <pthread.h> | |
#include <unistd.h> | |
void checkError(fdb_error_t errorNum) | |
{ | |
if(errorNum) { fprintf(stderr, "Error (%d): %s\n", errorNum, fdb_get_error(errorNum)); exit(errorNum); } | |
} | |
void waitAndCheckError(FDBFuture *future) | |
{ | |
checkError(fdb_future_block_until_ready(future)); | |
checkError(fdb_future_get_error(future)); | |
} | |
void runNetwork() | |
{ | |
checkError(fdb_run_network()); | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
puts("Starting FoundationDB C API Test"); | |
if(argc < 2) | |
{ | |
// use default cluster file if none specified | |
argv[1] ="/usr/local/etc/foundationdb/fdb.cluster"; | |
} | |
// set up network | |
checkError(fdb_select_api_version(FDB_API_VERSION)); | |
checkError(fdb_setup_network()); | |
puts("Got network"); | |
// run network | |
pthread_t netThread; | |
pthread_create(&netThread, NULL, (void *)runNetwork, NULL); | |
// get cluster | |
FDBFuture *clusterFuture = fdb_create_cluster(argv[1]); | |
waitAndCheckError(clusterFuture); | |
puts("Got cluster"); | |
// get database | |
FDBCluster *cluster; | |
checkError(fdb_future_get_cluster(clusterFuture, &cluster)); | |
fdb_future_destroy(clusterFuture); | |
FDBFuture *dbFuture = fdb_cluster_create_database(cluster, "DB", 2); | |
waitAndCheckError(dbFuture); | |
FDBDatabase *db; | |
checkError(fdb_future_get_database(dbFuture, &db)); | |
fdb_future_destroy(dbFuture); | |
puts("Got database"); | |
FDBTransaction *tr; | |
checkError(fdb_database_create_transaction(db, &tr)); | |
const uint8_t *key = "lul"; | |
int keylength = (int)strlen(key); | |
// leak happens here, the more cycles, the more memory it eats. currently on my machine 3m cycles is roughly 700 mb of RAM | |
for (int i = 0; i < 3000000; i++) { | |
fdb_transaction_clear(tr, key, keylength); | |
} | |
puts("DONE"); | |
FDBFuture *commitFuture = fdb_transaction_commit(tr); | |
checkError(fdb_future_block_until_ready(commitFuture)); | |
fdb_transaction_destroy(tr); | |
fdb_future_release_memory(commitFuture); | |
fdb_future_destroy(commitFuture); | |
sleep(60); | |
checkError(fdb_stop_network()); | |
fdb_database_destroy(db); | |
fdb_cluster_destroy(cluster); | |
puts("Program done. Now exiting..."); | |
pthread_exit(NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment