Skip to content

Commit 9e975fe

Browse files
committed
- Updating inline TODO notes
- Minor optimization for checking element size in typed buffer
1 parent 63c4c8b commit 9e975fe

7 files changed

Lines changed: 24 additions & 22 deletions

File tree

src/client/dbps_api_client.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ using namespace dbps::external;
2828
using namespace dbps::enum_utils;
2929

3030
// Generate a simple unique reference ID using timestamp
31-
// TODO: Potentially not-unique if concurrent calls are made on the same millisecond.
32-
// Can use atomic counters but may not be an issue to justify the complexity.
31+
32+
// Potential improvement:
33+
// - Potentially not-unique if concurrent calls are made on the same millisecond.
34+
// - Can use atomic counters but may not be an issue to justify the complexity.
3335
std::string GenerateReferenceId() {
3436
auto now = std::chrono::system_clock::now();
3537
auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(

src/common/dbpa_remote.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ std::unique_ptr<DecryptionResult> RemoteDataBatchProtectionAgent::Decrypt(span<c
341341
);
342342

343343
// Validate that response fields match request fields
344-
// TODO: Add validation for encoding when these are expanded beyond PLAIN.
344+
// Potential improvement: Add validation for encoding when these are expanded beyond PLAIN.
345345
if (response.Success()) {
346346
const auto& response_attrs = response.GetResponseAttributes();
347347

@@ -452,7 +452,7 @@ std::shared_ptr<HttpClientBase> RemoteDataBatchProtectionAgent::InstantiateHttpC
452452
// get the client for the given server_url_ with configured number of worker threads
453453
std::size_t num_worker_threads = ExtractNumWorkerThreads(*config_json_opt);
454454

455-
// TODO: Split credentials config file key and credentials file from connection config.
455+
// Potential improvement: Split credentials config file key and credentials file from connection config.
456456
HttpClientBase::ClientCredentials credentials = ExtractClientCredentials(*config_json_opt);
457457

458458
std::shared_ptr<HttpClientBase> http_client =
@@ -549,7 +549,7 @@ HttplibPoolRegistry::PoolConfig RemoteDataBatchProtectionAgent::ExtractPoolConfi
549549
pool_config.write_timeout = std::chrono::seconds(
550550
get_int_or_default(config_json, "connection_pool.write_timeout_seconds", HttplibPoolRegistry::kDefaultWriteTimeout_s.count()));
551551

552-
//TODO: find a better way to log this.
552+
//Potential improvement: find a better way to log this.
553553
// Log the configured pool values for observability
554554
std::cerr << "INFO: RemoteDataBatchProtectionAgent::init() - HTTP pool config {"
555555
<< " max_pool_size=" << pool_config.max_pool_size

src/common/dbpa_remote.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ class DBPS_EXPORT RemoteDataBatchProtectionAgent : public DataBatchProtectionAge
104104
// Constructor with HTTP client passed. Creates API_client immediately on the contructor.
105105
explicit RemoteDataBatchProtectionAgent(std::shared_ptr<HttpClientBase> http_client);
106106

107-
// TODO: Split credentials config file key and credentials file from connection config.
108-
// Currently these live on the same file, but should be separate as they may have different access permissions.
107+
// Potential improvement:
108+
// - Split credentials config file key and credentials file from connection config.
109+
// - Currently these live on the same file, but should be separate as they may have different access permissions.
110+
109111
// Configuration map keys
110112
inline static const std::string k_connection_config_key_ = "connection_config_file_path";
111113

src/common/json_request.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ std::string EncodeBase64Safe(const std::vector<uint8_t>& data) {
143143
}
144144
}
145145

146+
// Potential improvement: Unify usage of nlohmann or crow json for parsing and dumping.
147+
146148
// Allow strings or nested structures in the JSON payload for authentication credentials.
147-
// TODO(Issue #205): Unify usage of nlohmann or crow json for parsing and dumping.
148149
std::optional<std::string> TokenRequest::ParseWithError(const std::string& request_body) {
149150
credential_values_.clear();
150151

src/processing/parquet_utils.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ int CalculateLevelBytesLength(tcb::span<const uint8_t> raw,
239239
int32_t def_level_length = std::get<int32_t>(encoding_attribs.at("page_v2_definition_levels_byte_length"));
240240
int32_t rep_level_length = std::get<int32_t>(encoding_attribs.at("page_v2_repetition_levels_byte_length"));
241241
total_level_bytes = def_level_length + rep_level_length;
242+
242243
} else if (page_type == "DATA_PAGE_V1") {
243244
// Check that encoding types are RLE (instead of BIT_PACKED which is deprecated)
244245
const std::string& rep_encoding = std::get<std::string>(encoding_attribs.at("page_v1_repetition_level_encoding"));
@@ -301,7 +302,7 @@ LevelAndValueBytes DecompressAndSplit(
301302
auto page_type = std::get<std::string>(encoding_attributes.at("page_type"));
302303

303304
// On DATA_PAGE_V1, the whole payload is compressed.
304-
// So the split of level and value byte requires to
305+
// So the split of level and value byte requires to:
305306
// (1) decompress the whole payload, (2) calculate length of level bytes, (3) split into level and value bytes.
306307
if (page_type == "DATA_PAGE_V1") {
307308
auto decompressed_bytes = Decompress(plaintext, compression);
@@ -330,7 +331,7 @@ LevelAndValueBytes DecompressAndSplit(
330331
}
331332

332333
// On DATA_PAGE_V2, only the value bytes are compressed.
333-
// So the split of level and value byte requires to
334+
// So the split of level and value byte requires to:
334335
// (1) calculate length of level bytes, (2) split into level, (3) decompress only the value bytes.
335336
if (page_type == "DATA_PAGE_V2") {
336337
int leading_bytes_to_strip = CalculateLevelBytesLength(

src/processing/typed_buffer.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class ByteBuffer {
9696

9797
// Attribute for the number of elements in the buffer (a const)
9898
// - `num_elements_` is a const and passed during construction of both read-only and write buffers.
99-
// - It indicates the expected number of elements in the buffer payload declared upfront.
100-
// - This is treated as an invariant, so if the payload count mismatches, exceptions are thrown.
99+
// - It indicates the expected number of elements in the buffer payload.
100+
// - This is treated as an invariant. If the actual payload count mismatches, exceptions are thrown.
101101
const size_t num_elements_;
102102

103103
// Variables for element span iterator.
@@ -155,7 +155,7 @@ ByteBuffer<Codec>::ByteBuffer(
155155
Codec codec)
156156
: elements_span_(elements_span),
157157
elements_span_size_(elements_span.size()),
158-
// `num_elements_` is the expected number of elements in the buffer declared upfront.
158+
// `num_elements_` is the expected number of elements in the buffer.
159159
// - if the actual payload count mismatches, exceptions are thrown.
160160
num_elements_(num_elements),
161161
codec_(std::move(codec)),
@@ -206,15 +206,12 @@ inline void ByteBuffer<Codec>::InitializeFromSpan() const {
206206
// Fixed-size layout has implicit offsets from index * element_size.
207207
// We validate shape and derive element count. No need to store offsets.
208208
if constexpr (is_fixed_sized) {
209-
if (element_size_ <= 0) {
210-
throw InvalidInputException("Invalid fixed-size buffer: element_size must be greater than zero");
211-
}
212209
if ((readable_size % element_size_) != 0) {
213210
throw InvalidInputException("Malformed fixed-size buffer: buffer does not align with element_size");
214211
}
215212

216213
// Check if the num_elements passed at contruction time coincides with the calculated from the payload size.
217-
// This is a division of integer values, however it results in a correct integer result because of the modulo guard above.
214+
// Although this is a division of integers, the result is an integer (no remainder) because of the modulo guard above.
218215
const size_t num_elements_on_payload = readable_size / element_size_;
219216
if (num_elements_on_payload != num_elements_) {
220217
throw InvalidInputException("Malformed fixed-size buffer: num_elements on payload != num_elements_ expected.");
@@ -454,10 +451,6 @@ template <class Codec>
454451
inline void ByteBuffer<Codec>::InitializeForWriteBuffer(size_t variable_size_reserved_bytes_hint) {
455452
// Fixed-size elements
456453
if constexpr (is_fixed_sized) {
457-
if (element_size_ <= 0) {
458-
throw InvalidInputException("Invalid fixed-size buffer: element_size must be greater than zero");
459-
}
460-
461454
// write_buffer can be allocated to precise size since the element size and number of elements are known.
462455
// We initialize it to 0s to have random-ish access during writes.
463456
const size_t fixed_size_total_bytes = prefix_size_ + (num_elements_ * element_size_);

src/server/dbps_api_server.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ int main(int argc, char* argv[]) {
5555
// Initialize credentials file path and JWT secret key with parsed command line options
5656
std::optional<std::string> credentials_file_path = std::nullopt;
5757
std::string jwt_secret_key = "default-secret-key-overwritten-by-command-line";
58-
// TODO: Flip allow_missing_credentials=False when instructions are updated with the cmdline flags to run the server.
58+
59+
// `allow_missing_credentials` is set to true to allow a missing credentials file to be used.
60+
// This is useful for development and testing purposes, but should be set to false in production.
5961
bool allow_missing_credentials = true;
62+
6063
try {
6164
cxxopts::Options options("dbps_api_server", "Data Batch Protection Service API Server");
6265
options.add_options()

0 commit comments

Comments
 (0)