Skip to content

Commit

Permalink
Feature/api docs (#82)
Browse files Browse the repository at this point in the history
* API Docs
* Linting fixes
* release notes
* removed redundant hashing
* minor bugfixes
  • Loading branch information
DanEngelbrecht authored Jun 22, 2020
1 parent 0bf550f commit 2f0c212
Show file tree
Hide file tree
Showing 12 changed files with 605 additions and 172 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ jobs:
release_name: Release ${{ github.ref }}
body: |
Changes in this Release
- *CHANGED* Cacheblockstore uses ref count instead of full block copy when storing to local cache
- *FIXED* Hash map creations now pre-allocates capacity to avoid excessive memory allocations
- *ADDED* Added doxygen API documentation
- *FIXED* Linting issues and minor bug fixes
- *FIXED* Removed redundant hashing in DynamicChunking
draft: false
prerelease: false
- name: Download Linux artifacts
Expand Down
6 changes: 3 additions & 3 deletions cmd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ int UpSync(
if (source_version_index == 0)
{
struct Longtail_FileInfos* file_infos;
int err = Longtail_GetFilesRecursively(
err = Longtail_GetFilesRecursively(
storage_api,
0,
0,
Expand Down Expand Up @@ -698,7 +698,7 @@ int DownSync(
struct Longtail_VersionIndex* target_version_index = 0;
if (optional_target_index_path)
{
int err = Longtail_ReadVersionIndex(storage_api, optional_target_index_path, &target_version_index);
err = Longtail_ReadVersionIndex(storage_api, optional_target_index_path, &target_version_index);
if (err)
{
LONGTAIL_LOG(LONGTAIL_LOG_LEVEL_WARNING, "Failed to read version index from `%s`, %d", optional_target_index_path, err);
Expand All @@ -707,7 +707,7 @@ int DownSync(
if (target_version_index == 0)
{
struct Longtail_FileInfos* file_infos;
int err = Longtail_GetFilesRecursively(
err = Longtail_GetFilesRecursively(
storage_api,
0,
0,
Expand Down
4 changes: 2 additions & 2 deletions lib/atomiccancel/longtail_atomiccancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static int AtomicCancelAPI_CreateToken(struct Longtail_CancelAPI* cancel_api, Lo
LONGTAIL_VALIDATE_INPUT(cancel_api, return EINVAL )
LONGTAIL_VALIDATE_INPUT(out_token, return EINVAL )
struct AtomicCancelAPI* api = (struct AtomicCancelAPI*)cancel_api;
TLongtail_Atomic32* atomic_counter = (TLongtail_Atomic32*)Longtail_Alloc(sizeof(sizeof(TLongtail_Atomic32)));
TLongtail_Atomic32* atomic_counter = (TLongtail_Atomic32*)Longtail_Alloc(sizeof(TLongtail_Atomic32));
if (!atomic_counter)
{
LONGTAIL_LOG(LONGTAIL_LOG_LEVEL_ERROR, "AtomicCancelAPI_CreateToken(%p, %p) failed with %d",
Expand Down Expand Up @@ -55,7 +55,7 @@ static int AtomicCancelAPI_IsCancelled(struct Longtail_CancelAPI* cancel_api, Lo
struct AtomicCancelAPI* api = (struct AtomicCancelAPI*)cancel_api;
TLongtail_Atomic32* atomic_counter = (TLongtail_Atomic32*)token;
int32_t current_value = *atomic_counter;
if (*atomic_counter)
if (current_value)
{
return ECANCELED;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/bikeshed/longtail_bikeshed.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ struct Bikeshed_JobAPI_Group* CreateJobGroup(struct BikeshedJobAPI* job_api, uin
job_group->m_PendingJobCount = 0;
job_group->m_SubmittedJobCount = 0;
job_group->m_JobsCompleted = 0;
err = 0;
end:
return job_group;
on_error:
Expand Down Expand Up @@ -351,6 +350,7 @@ static int Bikeshed_WaitForAllJobs(struct Longtail_JobAPI* job_api, Longtail_Job
if (old_pending_count != bikeshed_job_group->m_PendingJobCount)
{
old_pending_count = bikeshed_job_group->m_PendingJobCount;
continue;
}
Longtail_WaitSema(bikeshed_job_api->m_ReadyCallback.m_Semaphore, 1000);
}
Expand Down
8 changes: 1 addition & 7 deletions lib/brotli/longtail_brotli.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ int BrotliCompressionAPI_Compress(
size_t* out_compressed_size)
{
struct BrotliSettings* brotli_settings = SettingsIDToCompressionSetting(settings_id);
if (brotli_settings == 0)
{
LONGTAIL_LOG(LONGTAIL_LOG_LEVEL_ERROR, "BrotliCompressionAPI_Compress(%p, %u, %p, %p, %" PRIu64 ", %" PRIu64 ", %p) invalid settings type %u",
compression_api, settings_id, uncompressed, compressed, uncompressed_size, max_compressed_size, out_compressed_size,
settings_id);
}
LONGTAIL_FATAL_ASSERT(brotli_settings != 0, return EINVAL);
LONGTAIL_VALIDATE_INPUT(brotli_settings != 0, return EINVAL)

*out_compressed_size = max_compressed_size;
if (BROTLI_FALSE == BrotliEncoderCompress(brotli_settings->m_Quality, brotli_settings->m_WindowBits, brotli_settings->m_Mode, uncompressed_size, (const uint8_t*)uncompressed, out_compressed_size, (uint8_t*)compressed))
Expand Down
8 changes: 4 additions & 4 deletions lib/compressionregistry/longtail_compression_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ static void DefaultCompressionRegistry_Dispose(struct Longtail_API* api)
struct Default_CompressionRegistry* default_compression_registry = (struct Default_CompressionRegistry*)api;
for (uint32_t c = 0; c < default_compression_registry->m_Count; ++c)
{
struct Longtail_CompressionAPI* api = default_compression_registry->m_APIs[c];
if (api != last_api)
struct Longtail_CompressionAPI* compression_api = default_compression_registry->m_APIs[c];
if (compression_api != last_api)
{
api->m_API.Dispose(&api->m_API);
last_api = api;
compression_api->m_API.Dispose(&compression_api->m_API);
last_api = compression_api;
}
}
Longtail_Free(default_compression_registry);
Expand Down
2 changes: 0 additions & 2 deletions lib/filestorage/longtail_filestorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ static int FSStorageAPI_StartFind(struct Longtail_StorageAPI* storage_api, const
if (err == ENOENT)
{
Longtail_Free(iterator);
iterator = 0;
return err;
}
if (err)
Expand All @@ -315,7 +314,6 @@ static int FSStorageAPI_StartFind(struct Longtail_StorageAPI* storage_api, const
storage_api, path, out_iterator,
err)
Longtail_Free(iterator);
iterator = 0;
return err;
}
*out_iterator = iterator;
Expand Down
14 changes: 0 additions & 14 deletions lib/fsblockstore/longtail_fsblockstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,6 @@ static int ReadContent(
return err;
}

const uint32_t default_path_count = 512;
const uint32_t default_path_data_size = default_path_count * 128;

uint32_t path_count = file_infos->m_Count;
if (path_count == 0)
{
Expand Down Expand Up @@ -279,7 +276,6 @@ static int ReadContent(
Longtail_Free((void*)chunks_path);
return err;
}
LONGTAIL_FATAL_ASSERT(!err, return err)

size_t block_indexes_size = sizeof(struct Longtail_BlockIndex*) * (path_count);
struct Longtail_BlockIndex** block_indexes = (struct Longtail_BlockIndex**)Longtail_Alloc(block_indexes_size);
Expand All @@ -295,14 +291,12 @@ static int ReadContent(
}

uint64_t block_count = 0;
uint64_t chunk_count = 0;
for (uint32_t path_index = 0; path_index < path_count; ++path_index)
{
struct ScanBlockJob* job = &scan_jobs[path_index];
if (job->m_Err == 0)
{
block_indexes[block_count] = job->m_BlockIndex;
chunk_count += *job->m_BlockIndex->m_ChunkCount;
++block_count;
}
}
Expand Down Expand Up @@ -384,9 +378,7 @@ static int FSBlockStore_PutStoredBlock(
hmdel(fsblockstore_api->m_BlockState, block_hash);
Longtail_UnlockSpinLock(fsblockstore_api->m_Lock);
Longtail_Free((char*)tmp_block_path);
tmp_block_path = 0;
Longtail_Free((char*)block_path);
block_path = 0;
return err;
}

Expand All @@ -400,9 +392,7 @@ static int FSBlockStore_PutStoredBlock(
hmdel(fsblockstore_api->m_BlockState, block_hash);
Longtail_UnlockSpinLock(fsblockstore_api->m_Lock);
Longtail_Free((char*)tmp_block_path);
tmp_block_path = 0;
Longtail_Free((char*)block_path);
block_path = 0;
return err;
}

Expand All @@ -426,9 +416,7 @@ static int FSBlockStore_PutStoredBlock(
hmdel(fsblockstore_api->m_BlockState, block_hash);
Longtail_UnlockSpinLock(fsblockstore_api->m_Lock);
Longtail_Free((char*)tmp_block_path);
tmp_block_path = 0;
Longtail_Free((char*)block_path);
block_path = 0;
return err;
}

Expand Down Expand Up @@ -524,15 +512,13 @@ static int FSBlockStore_GetStoredBlock(
block_store_api, block_hash, async_complete_api,
err)
Longtail_Free((char*)block_path);
block_path = 0;
return err;
}
Longtail_AtomicAdd64(&fsblockstore_api->m_BlocksGetCount, 1);
Longtail_AtomicAdd64(&fsblockstore_api->m_ChunksGetCount, *stored_block->m_BlockIndex->m_ChunkCount);
Longtail_AtomicAdd64(&fsblockstore_api->m_BytesGetCount, Longtail_GetBlockIndexDataSize(*stored_block->m_BlockIndex->m_ChunkCount) + stored_block->m_BlockChunksDataSize);

Longtail_Free(block_path);
block_path = 0;

async_complete_api->OnComplete(async_complete_api, stored_block, 0);
return 0;
Expand Down
8 changes: 4 additions & 4 deletions lib/hashregistry/longtail_hash_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ static void DefaultHashRegistry_Dispose(struct Longtail_API* api)
struct Default_HashRegistry* default_hash_registry = (struct Default_HashRegistry*)api;
for (uint32_t c = 0; c < default_hash_registry->m_Count; ++c)
{
struct Longtail_HashAPI* api = default_hash_registry->m_APIs[c];
if (api != last_api)
struct Longtail_HashAPI* hash_api = default_hash_registry->m_APIs[c];
if (hash_api != last_api)
{
api->m_API.Dispose(&api->m_API);
last_api = api;
hash_api->m_API.Dispose(&hash_api->m_API);
last_api = hash_api;
}
}
Longtail_Free(default_hash_registry);
Expand Down
6 changes: 4 additions & 2 deletions lib/longtail_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,17 @@ void Longtail_NormalizePath(char* path)
{
while (*path)
{
*path++ = *path == '\\' ? '/' : *path;
*path = ((*path) == '\\') ? '/' : (*path);
++path;
}
}

void Longtail_DenormalizePath(char* path)
{
while (*path)
{
*path++ = *path == '/' ? '\\' : *path;
*path = ((*path) == '/') ? '\\' : (*path);
++path;
}
}

Expand Down
Loading

0 comments on commit 2f0c212

Please sign in to comment.