Commit e3f45eb0 authored by Greg Williams's avatar Greg Williams
Browse files

Multi-threaded put is disabled for now, until deadlock is fixed.

Disabled logging for now.
parent 6ec5f5f2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
#!/bin/sh
# Run astyle on all C files in all project source folders
astyle --style=allman --break-blocks=all --pad-oper --pad-header --unpad-paren --align-pointer=type --add-brackets --convert-tabs --lineend=linux --recursive ./src/*.c ./src/*.h ./include/*.h
astyle --style=kr --break-closing-brackets --pad-oper --pad-header --unpad-paren --convert-tabs --indent=spaces=4 --lineend=linux --recursive ./src/*.c ./src/*.h ./include/*.h
+4 −1
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@
      - -Wextra
      - -pedantic
      - -D_POSIX_C_SOURCE=1
      - -D_C99_SOURCE=1
      - ${1}
  :test_compiler:
    :executable: gcc
@@ -122,7 +123,8 @@
      - -Wall
      - -Wextra
      - -pedantic
      - -D_POSIX_C_SOURCE=1
      - -D_C99_SOURCE=1
      - -D_DARWIN_C_SOURCE=1
      - -c ${1}
      - -o ${2}
  :test_linker:
@@ -153,6 +155,7 @@
      - -Wextra
      - -pedantic
      - -D_POSIX_C_SOURCE=1
      - -D_C99_SOURCE=1
      - -l crypto
      - -l ssl
      - "-c \"${1}\""
+34 −48
Original line number Diff line number Diff line
@@ -28,15 +28,17 @@ STATIC KineticPDUListItem* PDUListLast = NULL;
KineticPDU* KineticAllocator_NewPDU(void)
{
    KineticPDUListItem* newItem = (KineticPDUListItem*)malloc(sizeof(KineticPDUListItem));
    newItem->next = NULL;
    newItem->previous = NULL;
    if (newItem == NULL) {
        LOG("Failed allocating new PDU!");
        return NULL;
    }

    if (PDUList == NULL)
    {
    // Zero-out the new PDU and add it to the list
    memset(newItem, 0, sizeof(KineticPDUListItem));
    if (PDUList == NULL) {
        PDUList = newItem;
    }
    else
    {
    else {
        newItem->previous = PDUListLast;
        PDUListLast->next = newItem;
    }
@@ -51,70 +53,58 @@ KineticPDU* KineticAllocator_NewPDU(void)
void KineticAllocator_FreePDU(KineticPDU** pdu)
{
    KineticPDUListItem* cur = PDUList;
    while (&cur->pdu != *pdu)
    {
        if (cur->next == NULL)
        {
    while (&cur->pdu != *pdu) {
        if (cur->next == NULL) {
            LOG("  Reached end of list before finding PDU to free!");
            return;
        }
        else
        {
        else {
            LOG("  next..");
            cur = cur->next;
        }
    }
    LOG("  Done searching for PDU list item");

    if ((cur != NULL) && (&cur->pdu == *pdu))
    {
    if ((cur != NULL) && (&cur->pdu == *pdu)) {
        LOG("  PDU found! freeing it.");

        // Handle PDU list emptied
        if (cur->previous == NULL)
        {
        if (cur->previous == NULL) {
            LOG("  At start of list.");
            if (cur->next == NULL)
            {
            if (cur->next == NULL) {
                LOG("  Making it empty, since all deallocated!");
                PDUList = NULL;
                PDUListLast = NULL;
            }
            else
            {
            else {
                LOG("  Moving current item to head, since head deallocated!");
                PDUList = cur->next;
                PDUList->previous = NULL;
            }
        }
        else
        {
        else {
            // Relink from previous to next, if avaliable
            LOG("  Not at list start, so relinking list to free PDU.");
            if (cur->previous->next != NULL)
            {
            if (cur->previous->next != NULL) {
                LOG("  Relinking previous to next");
                if (cur->next != NULL)
                {
                if (cur->next != NULL) {
                    LOG("    next being reset!");
                    cur->previous->next = cur->next;
                }
                else
                {
                else {
                    PDUListLast = cur->previous;
                    PDUListLast->next = NULL;
                    LOGF("    next is NULL. End of list now @ 0x%0llX",
                         (long long)PDUListLast);
                }
            }
            else
            {
            else {
                LOG("  This shouldn't happen!");
                PDUListLast = cur->previous;
            }
        }

        if ((cur->pdu.proto != NULL) && cur->pdu.protobufDynamicallyExtracted)
        {
        if ((cur->pdu.proto != NULL) && cur->pdu.protobufDynamicallyExtracted) {
            KineticProto__free_unpacked(cur->pdu.proto, NULL);
            cur->pdu.proto = NULL;
            cur->pdu.protobufDynamicallyExtracted = false;
@@ -132,26 +122,22 @@ void KineticAllocator_FreePDU(KineticPDU** pdu)
void KineticAllocator_FreeAllPDUs(void)
{
    LOG_LOCATION;
    if (PDUList != NULL)
    {
    if (PDUList != NULL) {
        LOG("Freeing list of PDUs...");
        KineticPDUListItem* current = PDUList;

        while (current->next != NULL)
        {
        while (current->next != NULL) {
            LOG("Advancing to next list item...");
            current = current->next;
        }

        while (current != NULL)
        {
        while (current != NULL) {
            LOG("  Current item not freed!");
            LOGF("  DEALLOCATING item: 0x%0llX, pdu: 0x%llX, prev: 0x%0llX",
                 (long long)current, (long long)&current->pdu, (long long)current->previous);
            KineticPDUListItem* curItem = current;
            KineticPDUListItem* prevItem = current->previous;
            if (curItem != NULL)
            {
            if (curItem != NULL) {
                LOG("  Freeing list item");
                free(curItem);
            }
@@ -159,8 +145,7 @@ void KineticAllocator_FreeAllPDUs(void)
            LOGF("  on to prev=0x%llX", (long long)current);
        }
    }
    else
    {
    else {
        LOG("  Nothing to free!");
    }
    PDUList = NULL;
@@ -170,7 +155,8 @@ void KineticAllocator_FreeAllPDUs(void)
bool KineticAllocator_ValidateAllMemoryFreed(void)
{
    bool empty = (PDUList == NULL);
    LOG_LOCATION; LOGF("  PDUList: 0x%0llX, empty=%s",
    LOG_LOCATION;
    LOGF("  PDUList: 0x%0llX, empty=%s",
        (long long)PDUList, empty ? "true" : "false");
    return empty;
}
+15 −2
Original line number Diff line number Diff line
@@ -58,6 +58,16 @@ static KineticStatus KineticClient_ExecuteOperation(KineticOperation* operation)
{
    KineticStatus status = KINETIC_STATUS_INVALID;

    LOG_LOCATION; LOGF("Executing operation: 0x%llX", operation);
    if (operation->request->metadata != NULL) {
        KineticLogger_LogByteArray("  Sending PDU w/metadata:",
            operation->request->metadata->value);
    }
    else {
        LOG_LOCATION; LOG("  Sending PDU w/o metadata");
    }
    // KineticLogger_LogByteArray(" .value", operation->request->value);

    // Send the request
    if (KineticPDU_Send(operation->request))
    {
@@ -201,8 +211,7 @@ KineticStatus KineticClient_Get(KineticSessionHandle handle,
    KineticOperation operation;

    status = KineticClient_CreateOperation(&operation, handle);
    if (status != KINETIC_STATUS_SUCCESS)
    {
    if (status != KINETIC_STATUS_SUCCESS) {
        return status;
    }

@@ -238,14 +247,18 @@ KineticStatus KineticClient_Delete(KineticSessionHandle handle,
    KineticStatus status;
    KineticOperation operation;

LOG("Creating new operation!");
    status = KineticClient_CreateOperation(&operation, handle);
    if (status != KINETIC_STATUS_SUCCESS)
    {
        LOG("BOOM");
        return status;
    }

    // Initialize request
    KineticOperation_BuildDelete(&operation, metadata);
    LOG_LOCATION; KineticLogger_LogByteArray(
    "  DELETE REQUEST (post)", operation.request->value);

    // Execute the operation
    return KineticClient_ExecuteOperation(&operation);
+109 −79
Original line number Diff line number Diff line
@@ -25,31 +25,43 @@

static char LogFile[256] = "";
bool LogToConsole = true;
int LogLevel = 0;
FILE* FileDesc = NULL;

void KineticLogger_Init(const char* logFile)
{
    LogToConsole = true;
    FileDesc = NULL;
    if (logFile != NULL)
    {
        strcpy(LogFile, logFile);
        FileDesc = fopen(LogFile, "w");
        if (FileDesc == NULL)
        {
            fprintf(stderr,
                "Failed to initialize logger with file: "
                "fopen('%s') => FileDesc=%zd\n",
                logFile, (size_t)FileDesc);
        }
        else
        {
            fprintf(stderr,
                "Logging output to %s\n",
                logFile);
            LogToConsole = false;
        }
    }
    LogLevel = -1;

    return;

    // if (logFile != NULL)
    // {
    //     strcpy(LogFile, logFile);
    //     if (strcmp(logFile, "NONE") == 0)
    //     {
    //         LogLevel = -1;
    //         LogToConsole = false;
    //         return;
    //     }

    //     FileDesc = fopen(LogFile, "w");
    //     if (FileDesc == NULL)
    //     {
    //         fprintf(stderr,
    //             "Failed to initialize logger with file: "
    //             "fopen('%s') => FileDesc=%zd\n",
    //             logFile, (size_t)FileDesc);
    //     }
    //     else
    //     {
    //         fprintf(stderr,
    //             "Logging output to %s\n",
    //             logFile);
    //         LogToConsole = false;
    //     }
    // }
}

void KineticLogger_Close(void)
@@ -64,7 +76,7 @@ void KineticLogger_Close(void)

void KineticLogger_Log(const char* message)
{
    if (message == NULL)
    if (message == NULL || LogLevel < 0)
    {
        return;
    }
@@ -81,6 +93,8 @@ int KineticLogger_LogPrintf(const char* format, ...)
{
    int result = -1;

    if (LogLevel >= 0)
    {
        if (format != NULL)
        {
            va_list arg_ptr;
@@ -90,6 +104,7 @@ int KineticLogger_LogPrintf(const char* format, ...)
            KineticLogger_Log(buffer);
            va_end(arg_ptr);
        }
    }

   return(result);
}
@@ -97,6 +112,8 @@ int KineticLogger_LogPrintf(const char* format, ...)

void KineticLogger_LogHeader(const KineticPDUHeader* header)
{
    if (LogLevel < 0) {return;}

    LOG("PDU Header:");
    LOGF("  versionPrefix: %c", header->versionPrefix);
    LOGF("  protobufLength: %d", header->protobufLength);
@@ -161,6 +178,8 @@ int KineticLogger_ByteArraySliceToCString(char* p_buf,

void KineticLogger_LogProtobuf(const KineticProto* proto)
{
    if (LogLevel < 0) {return;}

    LOG_PROTO_INIT();
    char tmpBuf[1024];

@@ -237,58 +256,58 @@ void KineticLogger_LogProtobuf(const KineticProto* proto)
                {
                    LOG_PROTO_LEVEL_START("keyValue");
                    {
                        // if (proto->command->body->keyValue->has_key)
                        // {
                        //     BYTES_TO_CSTRING(tmpBuf,
                        //         proto->command->body->keyValue->key, 0,
                        //         proto->command->body->keyValue->key.len);
                        //     LOGF("%skey: '%s'", _indent, tmpBuf);
                        // }
                        // if (proto->command->body->keyValue->has_newVersion)
                        // {
                        //     BYTES_TO_CSTRING(tmpBuf,
                        //         proto->command->body->keyValue->newVersion,
                        //         0, proto->command->body->keyValue->newVersion.len);
                        //     LOGF("%snewVersion: '%s'", _indent, tmpBuf);
                        // }
                        // if (proto->command->body->keyValue->has_dbVersion)
                        // {
                        //     BYTES_TO_CSTRING(tmpBuf,
                        //         proto->command->body->keyValue->dbVersion,
                        //         0, proto->command->body->keyValue->dbVersion.len);
                        //     LOGF("%sdbVersion: '%s'", _indent, tmpBuf);
                        // }
                        // if (proto->command->body->keyValue->has_tag)
                        // {
                        //     BYTES_TO_CSTRING(tmpBuf,
                        //         proto->command->body->keyValue->tag,
                        //         0, proto->command->body->keyValue->tag.len);
                        //     LOGF("%stag: '%s'", _indent, tmpBuf);
                        // }
                        // if (proto->command->body->keyValue->has_force)
                        // {
                        //     LOGF("%sforce: %s", _indent,
                        //         proto->command->body->keyValue->force ? _str_true : _str_false);
                        // }
                        // if (proto->command->body->keyValue->has_algorithm)
                        // {
                        //     const ProtobufCEnumValue* eVal = protobuf_c_enum_descriptor_get_value(
                        //         &KineticProto_algorithm__descriptor,
                        //         proto->command->body->keyValue->algorithm);
                        //     LOGF("%salgorithm: %s", _indent, eVal->name);
                        // }
                        // if (proto->command->body->keyValue->has_metadataOnly)
                        // {
                        //     LOGF("%smetadataOnly: %s", _indent,
                        //         proto->command->body->keyValue->metadataOnly ? _str_true : _str_false);
                        // }
                        // if (proto->command->body->keyValue->has_synchronization)
                        // {
                        //     const ProtobufCEnumValue* eVal = protobuf_c_enum_descriptor_get_value(
                        //         &KineticProto_synchronization__descriptor,
                        //         proto->command->body->keyValue->synchronization);
                        //     LOGF("%ssynchronization: %s", _indent, eVal->name);
                        // }
                        if (proto->command->body->keyValue->has_key)
                        {
                            BYTES_TO_CSTRING(tmpBuf,
                                proto->command->body->keyValue->key, 0,
                                proto->command->body->keyValue->key.len);
                            LOGF("%skey: '%s'", _indent, tmpBuf);
                        }
                        if (proto->command->body->keyValue->has_newVersion)
                        {
                            BYTES_TO_CSTRING(tmpBuf,
                                proto->command->body->keyValue->newVersion,
                                0, proto->command->body->keyValue->newVersion.len);
                            LOGF("%snewVersion: '%s'", _indent, tmpBuf);
                        }
                        if (proto->command->body->keyValue->has_dbVersion)
                        {
                            BYTES_TO_CSTRING(tmpBuf,
                                proto->command->body->keyValue->dbVersion,
                                0, proto->command->body->keyValue->dbVersion.len);
                            LOGF("%sdbVersion: '%s'", _indent, tmpBuf);
                        }
                        if (proto->command->body->keyValue->has_tag)
                        {
                            BYTES_TO_CSTRING(tmpBuf,
                                proto->command->body->keyValue->tag,
                                0, proto->command->body->keyValue->tag.len);
                            LOGF("%stag: '%s'", _indent, tmpBuf);
                        }
                        if (proto->command->body->keyValue->has_force)
                        {
                            LOGF("%sforce: %s", _indent,
                                proto->command->body->keyValue->force ? _str_true : _str_false);
                        }
                        if (proto->command->body->keyValue->has_algorithm)
                        {
                            const ProtobufCEnumValue* eVal = protobuf_c_enum_descriptor_get_value(
                                &KineticProto_algorithm__descriptor,
                                proto->command->body->keyValue->algorithm);
                            LOGF("%salgorithm: %s", _indent, eVal->name);
                        }
                        if (proto->command->body->keyValue->has_metadataOnly)
                        {
                            LOGF("%smetadataOnly: %s", _indent,
                                proto->command->body->keyValue->metadataOnly ? _str_true : _str_false);
                        }
                        if (proto->command->body->keyValue->has_synchronization)
                        {
                            const ProtobufCEnumValue* eVal = protobuf_c_enum_descriptor_get_value(
                                &KineticProto_synchronization__descriptor,
                                proto->command->body->keyValue->synchronization);
                            LOGF("%ssynchronization: %s", _indent, eVal->name);
                        }
                    }
                    LOG_PROTO_LEVEL_END();
                }
@@ -337,6 +356,8 @@ void KineticLogger_LogProtobuf(const KineticProto* proto)

void KineticLogger_LogStatus(KineticProto_Status* status)
{
    if (LogLevel < 0) {return;}

    ProtobufCMessage* protoMessage = (ProtobufCMessage*)status;
    KineticProto_Status_StatusCode code = status->code;

@@ -396,6 +417,15 @@ void KineticLogger_LogStatus(KineticProto_Status* status)

void KineticLogger_LogByteArray(const char* title, ByteArray bytes)
{
    if (LogLevel < 0) {return;}

    assert(title != NULL);
    if (bytes.data == NULL) {
        LOGF("%s: (??? bytes : buffer is NULL)", title); return;
    }
    if (bytes.data == NULL) {
        LOGF("%s: (0 bytes)", title); return;
    }
    LOGF("%s: (%zd bytes)", title, bytes.len);
    const int byteChars = 4;
    const int bytesPerLine = 16;
Loading