couchbase 3.1.1-universal-darwin-20 → 3.2.0-universal-darwin-20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/CMakeLists.txt +3 -1
- data/ext/build_version.hxx.in +1 -1
- data/ext/cmake/Testing.cmake +1 -0
- data/ext/cmake/ThirdPartyDependencies.cmake +6 -0
- data/ext/cmake/VersionInfo.cmake +3 -0
- data/ext/couchbase/bucket.hxx +47 -28
- data/ext/couchbase/cbsasl/client.h +1 -1
- data/ext/couchbase/cbsasl/context.cc +1 -1
- data/ext/couchbase/cbsasl/context.h +3 -3
- data/ext/couchbase/cbsasl/mechanism.cc +5 -8
- data/ext/couchbase/cbsasl/mechanism.h +1 -4
- data/ext/couchbase/cbsasl/plain/plain.cc +1 -1
- data/ext/couchbase/cbsasl/scram-sha/scram-sha.cc +30 -36
- data/ext/couchbase/cluster.hxx +40 -22
- data/ext/couchbase/cluster_options.hxx +7 -1
- data/ext/couchbase/configuration.hxx +37 -16
- data/ext/couchbase/couchbase.cxx +1145 -291
- data/ext/couchbase/error_map.hxx +1 -1
- data/ext/couchbase/errors.hxx +25 -17
- data/ext/couchbase/io/dns_client.hxx +3 -3
- data/ext/couchbase/io/dns_codec.hxx +4 -5
- data/ext/couchbase/io/dns_config.hxx +5 -6
- data/ext/couchbase/io/dns_message.hxx +3 -3
- data/ext/couchbase/io/http_command.hxx +70 -35
- data/ext/couchbase/io/http_session.hxx +4 -3
- data/ext/couchbase/io/http_session_manager.hxx +28 -19
- data/ext/couchbase/io/mcbp_command.hxx +51 -19
- data/ext/couchbase/io/mcbp_context.hxx +1 -1
- data/ext/couchbase/io/mcbp_parser.hxx +4 -4
- data/ext/couchbase/io/mcbp_session.hxx +91 -101
- data/ext/couchbase/io/query_cache.hxx +2 -2
- data/ext/couchbase/io/retry_orchestrator.hxx +2 -4
- data/ext/couchbase/io/retry_reason.hxx +2 -2
- data/ext/couchbase/io/retry_strategy.hxx +1 -6
- data/ext/couchbase/io/streams.hxx +7 -7
- data/ext/couchbase/metrics/logging_meter.hxx +228 -0
- data/ext/couchbase/metrics/logging_meter_options.hxx +28 -0
- data/ext/couchbase/metrics/meter.hxx +49 -0
- data/ext/couchbase/metrics/noop_meter.hxx +43 -0
- data/ext/couchbase/operations.hxx +4 -0
- data/ext/couchbase/operations/analytics_dataset_create.hxx +16 -12
- data/ext/couchbase/operations/analytics_dataset_drop.hxx +11 -11
- data/ext/couchbase/operations/analytics_dataset_get_all.hxx +6 -6
- data/ext/couchbase/operations/analytics_dataverse_create.hxx +10 -11
- data/ext/couchbase/operations/analytics_dataverse_drop.hxx +10 -11
- data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +9 -11
- data/ext/couchbase/operations/analytics_index_create.hxx +14 -13
- data/ext/couchbase/operations/analytics_index_drop.hxx +18 -12
- data/ext/couchbase/operations/analytics_index_get_all.hxx +8 -6
- data/ext/couchbase/operations/analytics_link.hxx +39 -0
- data/ext/couchbase/operations/analytics_link_azure_blob_external.hxx +145 -0
- data/ext/couchbase/operations/analytics_link_connect.hxx +14 -12
- data/ext/couchbase/operations/analytics_link_couchbase_remote.hxx +220 -0
- data/ext/couchbase/operations/analytics_link_create.hxx +128 -0
- data/ext/couchbase/operations/analytics_link_disconnect.hxx +11 -12
- data/ext/couchbase/operations/analytics_link_drop.hxx +130 -0
- data/ext/couchbase/operations/analytics_link_get_all.hxx +160 -0
- data/ext/couchbase/operations/analytics_link_replace.hxx +128 -0
- data/ext/couchbase/operations/analytics_link_s3_external.hxx +122 -0
- data/ext/couchbase/operations/bucket_create.hxx +8 -8
- data/ext/couchbase/operations/bucket_drop.hxx +5 -5
- data/ext/couchbase/operations/bucket_flush.hxx +5 -5
- data/ext/couchbase/operations/bucket_get.hxx +7 -7
- data/ext/couchbase/operations/bucket_get_all.hxx +7 -5
- data/ext/couchbase/operations/bucket_settings.hxx +40 -49
- data/ext/couchbase/operations/bucket_update.hxx +8 -8
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +7 -7
- data/ext/couchbase/operations/collection_create.hxx +11 -11
- data/ext/couchbase/operations/collection_drop.hxx +12 -10
- data/ext/couchbase/operations/collections_manifest_get.hxx +3 -3
- data/ext/couchbase/operations/design_document.hxx +2 -2
- data/ext/couchbase/operations/document_analytics.hxx +29 -36
- data/ext/couchbase/operations/document_append.hxx +3 -3
- data/ext/couchbase/operations/document_decrement.hxx +3 -3
- data/ext/couchbase/operations/document_exists.hxx +2 -2
- data/ext/couchbase/operations/document_get.hxx +3 -3
- data/ext/couchbase/operations/document_get_and_lock.hxx +5 -3
- data/ext/couchbase/operations/document_get_and_touch.hxx +5 -3
- data/ext/couchbase/operations/document_get_projected.hxx +10 -11
- data/ext/couchbase/operations/document_increment.hxx +3 -3
- data/ext/couchbase/operations/document_insert.hxx +3 -3
- data/ext/couchbase/operations/document_lookup_in.hxx +12 -18
- data/ext/couchbase/operations/document_mutate_in.hxx +13 -18
- data/ext/couchbase/operations/document_prepend.hxx +3 -3
- data/ext/couchbase/operations/document_query.hxx +39 -41
- data/ext/couchbase/operations/document_remove.hxx +3 -3
- data/ext/couchbase/operations/document_replace.hxx +3 -3
- data/ext/couchbase/operations/document_search.hxx +56 -61
- data/ext/couchbase/operations/document_touch.hxx +3 -3
- data/ext/couchbase/operations/document_unlock.hxx +3 -3
- data/ext/couchbase/operations/document_upsert.hxx +3 -3
- data/ext/couchbase/operations/document_view.hxx +23 -23
- data/ext/couchbase/operations/group_drop.hxx +5 -5
- data/ext/couchbase/operations/group_get.hxx +7 -7
- data/ext/couchbase/operations/group_get_all.hxx +6 -6
- data/ext/couchbase/operations/group_upsert.hxx +11 -11
- data/ext/couchbase/operations/http_noop.hxx +6 -6
- data/ext/couchbase/operations/mcbp_noop.hxx +3 -3
- data/ext/couchbase/operations/query_index_build_deferred.hxx +6 -6
- data/ext/couchbase/operations/query_index_create.hxx +10 -8
- data/ext/couchbase/operations/query_index_drop.hxx +8 -8
- data/ext/couchbase/operations/query_index_get_all.hxx +43 -39
- data/ext/couchbase/operations/rbac.hxx +40 -63
- data/ext/couchbase/operations/role_get_all.hxx +6 -6
- data/ext/couchbase/operations/scope_create.hxx +10 -10
- data/ext/couchbase/operations/scope_drop.hxx +9 -9
- data/ext/couchbase/operations/scope_get_all.hxx +8 -8
- data/ext/couchbase/operations/search_get_stats.hxx +5 -3
- data/ext/couchbase/operations/search_index.hxx +6 -15
- data/ext/couchbase/operations/search_index_analyze_document.hxx +11 -11
- data/ext/couchbase/operations/search_index_control_ingest.hxx +9 -9
- data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +9 -9
- data/ext/couchbase/operations/search_index_control_query.hxx +9 -9
- data/ext/couchbase/operations/search_index_drop.hxx +11 -9
- data/ext/couchbase/operations/search_index_get.hxx +11 -9
- data/ext/couchbase/operations/search_index_get_all.hxx +11 -11
- data/ext/couchbase/operations/search_index_get_documents_count.hxx +10 -10
- data/ext/couchbase/operations/search_index_get_stats.hxx +10 -8
- data/ext/couchbase/operations/search_index_upsert.hxx +12 -10
- data/ext/couchbase/operations/user_drop.hxx +5 -5
- data/ext/couchbase/operations/user_get.hxx +7 -7
- data/ext/couchbase/operations/user_get_all.hxx +6 -6
- data/ext/couchbase/operations/user_upsert.hxx +9 -9
- data/ext/couchbase/operations/view_index_drop.hxx +10 -10
- data/ext/couchbase/operations/view_index_get.hxx +13 -15
- data/ext/couchbase/operations/view_index_get_all.hxx +17 -20
- data/ext/couchbase/operations/view_index_upsert.hxx +9 -7
- data/ext/couchbase/origin.hxx +14 -10
- data/ext/couchbase/platform/backtrace.c +1 -1
- data/ext/couchbase/platform/base64.cc +5 -5
- data/ext/couchbase/platform/base64.h +2 -5
- data/ext/couchbase/protocol/client_opcode.hxx +7 -4
- data/ext/couchbase/protocol/client_request.hxx +2 -2
- data/ext/couchbase/protocol/client_response.hxx +41 -16
- data/ext/couchbase/protocol/cmd_append.hxx +17 -16
- data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +4 -4
- data/ext/couchbase/protocol/cmd_decrement.hxx +10 -11
- data/ext/couchbase/protocol/cmd_exists.hxx +12 -15
- data/ext/couchbase/protocol/cmd_get.hxx +11 -14
- data/ext/couchbase/protocol/cmd_get_and_lock.hxx +10 -12
- data/ext/couchbase/protocol/cmd_get_and_touch.hxx +10 -12
- data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +13 -18
- data/ext/couchbase/protocol/cmd_get_collection_id.hxx +12 -15
- data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +12 -16
- data/ext/couchbase/protocol/cmd_get_error_map.hxx +14 -17
- data/ext/couchbase/protocol/cmd_hello.hxx +8 -10
- data/ext/couchbase/protocol/cmd_increment.hxx +9 -10
- data/ext/couchbase/protocol/cmd_insert.hxx +9 -9
- data/ext/couchbase/protocol/cmd_lookup_in.hxx +12 -13
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +11 -11
- data/ext/couchbase/protocol/cmd_noop.hxx +16 -20
- data/ext/couchbase/protocol/cmd_prepend.hxx +9 -10
- data/ext/couchbase/protocol/cmd_remove.hxx +10 -13
- data/ext/couchbase/protocol/cmd_replace.hxx +7 -7
- data/ext/couchbase/protocol/cmd_sasl_auth.hxx +8 -10
- data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +10 -15
- data/ext/couchbase/protocol/cmd_sasl_step.hxx +10 -12
- data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -18
- data/ext/couchbase/protocol/cmd_touch.hxx +8 -11
- data/ext/couchbase/protocol/cmd_unlock.hxx +10 -14
- data/ext/couchbase/protocol/cmd_upsert.hxx +8 -8
- data/ext/couchbase/protocol/datatype.hxx +3 -3
- data/ext/couchbase/protocol/durability_level.hxx +2 -2
- data/ext/couchbase/protocol/frame_info_id.hxx +4 -4
- data/ext/couchbase/protocol/hello_feature.hxx +2 -2
- data/ext/couchbase/protocol/magic.hxx +2 -2
- data/ext/couchbase/protocol/server_opcode.hxx +2 -2
- data/ext/couchbase/protocol/server_request.hxx +1 -1
- data/ext/couchbase/protocol/status.hxx +4 -7
- data/ext/couchbase/protocol/unsigned_leb128.h +5 -20
- data/ext/couchbase/service_type.hxx +4 -4
- data/ext/couchbase/tracing/constants.hxx +261 -0
- data/ext/couchbase/tracing/noop_tracer.hxx +50 -0
- data/ext/couchbase/tracing/request_tracer.hxx +77 -0
- data/ext/couchbase/tracing/threshold_logging_options.hxx +64 -0
- data/ext/couchbase/tracing/threshold_logging_tracer.hxx +366 -0
- data/ext/couchbase/utils/byteswap.hxx +1 -1
- data/ext/couchbase/utils/connection_string.hxx +21 -1
- data/ext/couchbase/utils/name_codec.hxx +41 -0
- data/ext/couchbase/utils/url_codec.hxx +236 -0
- data/ext/couchbase/version.hxx +1 -1
- data/ext/test/CMakeLists.txt +1 -0
- data/ext/test/test_native_trivial_query.cxx +60 -0
- data/ext/third_party/hdr_histogram_c/CMakeLists.txt +84 -0
- data/ext/third_party/hdr_histogram_c/COPYING.txt +121 -0
- data/ext/third_party/hdr_histogram_c/LICENSE.txt +41 -0
- data/ext/third_party/hdr_histogram_c/config.cmake.in +6 -0
- data/ext/third_party/hdr_histogram_c/src/CMakeLists.txt +83 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_atomic.h +146 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_encoding.c +322 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_encoding.h +79 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_endian.h +116 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram.c +1196 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram.h +516 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.c +1290 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.h +236 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log_no_op.c +171 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.c +227 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.h +109 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_malloc.h +19 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_tests.h +22 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_thread.c +108 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_thread.h +55 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_time.c +98 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_time.h +49 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.c +143 -0
- data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.h +51 -0
- data/lib/couchbase/cluster.rb +1 -0
- data/lib/couchbase/errors.rb +3 -0
- data/lib/couchbase/libcouchbase.bundle +0 -0
- data/lib/couchbase/management/analytics_index_manager.rb +920 -226
- data/lib/couchbase/management/bucket_manager.rb +207 -69
- data/lib/couchbase/management/collection_manager.rb +173 -61
- data/lib/couchbase/management/query_index_manager.rb +357 -169
- data/lib/couchbase/options.rb +75 -3
- data/lib/couchbase/scope.rb +102 -0
- data/lib/couchbase/utils/time.rb +4 -0
- data/lib/couchbase/version.rb +6 -6
- metadata +48 -5
@@ -0,0 +1,236 @@
|
|
1
|
+
/**
|
2
|
+
* hdr_histogram_log.h
|
3
|
+
* Written by Michael Barker and released to the public domain,
|
4
|
+
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
|
5
|
+
*
|
6
|
+
* The implementation makes use of zlib to provide compression. You will need
|
7
|
+
* to link against -lz in order to link applications that include this header.
|
8
|
+
*/
|
9
|
+
|
10
|
+
#ifndef HDR_HISTOGRAM_H_LOG
|
11
|
+
#define HDR_HISTOGRAM_H_LOG 1
|
12
|
+
|
13
|
+
#define HDR_COMPRESSION_COOKIE_MISMATCH -29999
|
14
|
+
#define HDR_ENCODING_COOKIE_MISMATCH -29998
|
15
|
+
#define HDR_DEFLATE_INIT_FAIL -29997
|
16
|
+
#define HDR_DEFLATE_FAIL -29996
|
17
|
+
#define HDR_INFLATE_INIT_FAIL -29995
|
18
|
+
#define HDR_INFLATE_FAIL -29994
|
19
|
+
#define HDR_LOG_INVALID_VERSION -29993
|
20
|
+
#define HDR_TRAILING_ZEROS_INVALID -29992
|
21
|
+
#define HDR_VALUE_TRUNCATED -29991
|
22
|
+
#define HDR_ENCODED_INPUT_TOO_LONG -29990
|
23
|
+
|
24
|
+
#define HDR_LOG_TAG_MAX_BUFFER_LEN (1024)
|
25
|
+
|
26
|
+
#include <stdint.h>
|
27
|
+
#include <stdbool.h>
|
28
|
+
#include <stdio.h>
|
29
|
+
|
30
|
+
#include "hdr_time.h"
|
31
|
+
#include "hdr_histogram.h"
|
32
|
+
|
33
|
+
#ifdef __cplusplus
|
34
|
+
extern "C" {
|
35
|
+
#endif
|
36
|
+
|
37
|
+
/**
|
38
|
+
* Encode and compress the histogram with gzip.
|
39
|
+
*/
|
40
|
+
int hdr_log_encode(struct hdr_histogram* histogram, char** encoded_histogram);
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Decode and decompress the histogram with gzip.
|
44
|
+
*/
|
45
|
+
int hdr_log_decode(struct hdr_histogram** histogram, char* base64_histogram, size_t base64_len);
|
46
|
+
|
47
|
+
struct hdr_log_entry
|
48
|
+
{
|
49
|
+
hdr_timespec start_timestamp;
|
50
|
+
hdr_timespec interval;
|
51
|
+
hdr_timespec max;
|
52
|
+
char *tag;
|
53
|
+
size_t tag_len;
|
54
|
+
};
|
55
|
+
|
56
|
+
struct hdr_log_writer
|
57
|
+
{
|
58
|
+
uint32_t nonce;
|
59
|
+
};
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Initialise the log writer.
|
63
|
+
*
|
64
|
+
* @param writer 'This' pointer
|
65
|
+
* @return 0 on success.
|
66
|
+
*/
|
67
|
+
int hdr_log_writer_init(struct hdr_log_writer* writer);
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Write the header to the log, this will constist of a user defined string,
|
71
|
+
* the current timestamp, version information and the CSV header.
|
72
|
+
*
|
73
|
+
* @param writer 'This' pointer
|
74
|
+
* @param file The stream to output the log header to.
|
75
|
+
* @param user_prefix User defined string to include in the header.
|
76
|
+
* @param timestamp The start time that the histogram started recording from.
|
77
|
+
* @return Will return 0 if it successfully completed or an error number if there
|
78
|
+
* was a failure. EIO if the write failed.
|
79
|
+
*/
|
80
|
+
int hdr_log_write_header(
|
81
|
+
struct hdr_log_writer* writer,
|
82
|
+
FILE* file,
|
83
|
+
const char* user_prefix,
|
84
|
+
hdr_timespec* timestamp);
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Write an hdr_histogram entry to the log. It will be encoded in a similar
|
88
|
+
* fashion to the approach used by the Java version of the HdrHistogram. It will
|
89
|
+
* be a CSV line consisting of <start timestamp>,<end timestamp>,<max>,<histogram>
|
90
|
+
* where <histogram> is the binary histogram gzip compressed and base64 encoded.
|
91
|
+
*
|
92
|
+
* Timestamp is a bit of misnomer for the start_timestamp and end_timestamp values
|
93
|
+
* these could be offsets, e.g. start_timestamp could be offset from process start
|
94
|
+
* time and end_timestamp could actually be the length of the recorded interval.
|
95
|
+
*
|
96
|
+
* @param writer 'This' pointer
|
97
|
+
* @param file The stream to write the entry to.
|
98
|
+
* @param start_timestamp The start timestamp to include in the logged entry.
|
99
|
+
* @param end_timestamp The end timestamp to include in the logged entry.
|
100
|
+
* @param histogram The histogram to encode and log.
|
101
|
+
* @return Will return 0 if it successfully completed or an error number if there
|
102
|
+
* was a failure. Errors include HDR_DEFLATE_INIT_FAIL, HDR_DEFLATE_FAIL if
|
103
|
+
* something when wrong during gzip compression. ENOMEM if we failed to allocate
|
104
|
+
* or reallocate the buffer used for encoding (out of memory problem). EIO if
|
105
|
+
* write failed.
|
106
|
+
*/
|
107
|
+
int hdr_log_write(
|
108
|
+
struct hdr_log_writer* writer,
|
109
|
+
FILE* file,
|
110
|
+
const hdr_timespec* start_timestamp,
|
111
|
+
const hdr_timespec* end_timestamp,
|
112
|
+
struct hdr_histogram* histogram);
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Write an hdr_histogram entry to the log. It will be encoded in a similar
|
116
|
+
* fashion to the approach used by the Java version of the HdrHistogram. It will
|
117
|
+
* be a CSV line consisting of [Tag=XXX,]<start timestamp>,<end timestamp>,<max>,<histogram>
|
118
|
+
* where <histogram> is the binary histogram gzip compressed and base64 encoded.
|
119
|
+
*
|
120
|
+
* The tag is option and will only be written if the tag is non-NULL and the tag_len is
|
121
|
+
* greater than 0.
|
122
|
+
*
|
123
|
+
* Timestamp is a bit of misnomer for the start_timestamp and end_timestamp values
|
124
|
+
* these could be offsets, e.g. start_timestamp could be offset from process start
|
125
|
+
* time and end_timestamp could actually be the length of the recorded interval.
|
126
|
+
*
|
127
|
+
* @param writer 'This' pointer
|
128
|
+
* @param file The stream to write the entry to.
|
129
|
+
* @param entry Prefix information for the log line, including timestamps and tag.
|
130
|
+
* @param histogram The histogram to encode and log.
|
131
|
+
* @return Will return 0 if it successfully completed or an error number if there
|
132
|
+
* was a failure. Errors include HDR_DEFLATE_INIT_FAIL, HDR_DEFLATE_FAIL if
|
133
|
+
* something when wrong during gzip compression. ENOMEM if we failed to allocate
|
134
|
+
* or reallocate the buffer used for encoding (out of memory problem). EIO if
|
135
|
+
* write failed.
|
136
|
+
*/
|
137
|
+
int hdr_log_write_entry(
|
138
|
+
struct hdr_log_writer* writer,
|
139
|
+
FILE* file,
|
140
|
+
struct hdr_log_entry* entry,
|
141
|
+
struct hdr_histogram* histogram);
|
142
|
+
|
143
|
+
struct hdr_log_reader
|
144
|
+
{
|
145
|
+
int major_version;
|
146
|
+
int minor_version;
|
147
|
+
hdr_timespec start_timestamp;
|
148
|
+
};
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Initialise the log reader.
|
152
|
+
*
|
153
|
+
* @param reader 'This' pointer
|
154
|
+
* @return 0 on success
|
155
|
+
*/
|
156
|
+
int hdr_log_reader_init(struct hdr_log_reader* reader);
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Reads the the header information from the log. Will capure information
|
160
|
+
* such as version number and start timestamp from the header.
|
161
|
+
*
|
162
|
+
* @param hdr_log_reader 'This' pointer
|
163
|
+
* @param file The data stream to read from.
|
164
|
+
* @return 0 on success. An error number on failure.
|
165
|
+
*/
|
166
|
+
int hdr_log_read_header(struct hdr_log_reader* reader, FILE* file);
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Reads an entry from the log filling in the specified histogram, timestamp and
|
170
|
+
* interval values. If the supplied pointer to the histogram for this method is
|
171
|
+
* NULL then a new histogram will be allocated for the caller, however it will
|
172
|
+
* become the callers responsibility to free it later. If the pointer is non-null
|
173
|
+
* the histogram read from the log will be merged with the supplied histogram.
|
174
|
+
*
|
175
|
+
* @param reader 'This' pointer
|
176
|
+
* @param file The stream to read the histogram from.
|
177
|
+
* @param histogram Pointer to allocate a histogram to or merge into.
|
178
|
+
* @param timestamp The first timestamp from the CSV entry.
|
179
|
+
* @param interval The second timestamp from the CSV entry
|
180
|
+
* @return Will return 0 on success or an error number if there was some wrong
|
181
|
+
* when reading in the histogram. EOF (-1) will indicate that there are no more
|
182
|
+
* histograms left to be read from 'file'.
|
183
|
+
* HDR_INFLATE_INIT_FAIL or HDR_INFLATE_FAIL if
|
184
|
+
* there was a problem with Gzip. HDR_COMPRESSION_COOKIE_MISMATCH or
|
185
|
+
* HDR_ENCODING_COOKIE_MISMATCH if the cookie values are incorrect.
|
186
|
+
* HDR_LOG_INVALID_VERSION if the log can not be parsed. ENOMEM if buffer space
|
187
|
+
* or the histogram can not be allocated. EIO if there was an error during
|
188
|
+
* the read. EINVAL in any input values are incorrect.
|
189
|
+
*/
|
190
|
+
int hdr_log_read(
|
191
|
+
struct hdr_log_reader* reader, FILE* file, struct hdr_histogram** histogram,
|
192
|
+
hdr_timespec* timestamp, hdr_timespec* interval);
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Reads an entry from the log filling in the specified histogram and log entry struct.
|
196
|
+
* If the supplied pointer to the histogram for this method is
|
197
|
+
* NULL then a new histogram will be allocated for the caller, however it will
|
198
|
+
* become the callers responsibility to free it later. If the pointer is non-null
|
199
|
+
* the histogram read from the log will be merged with the supplied histogram.
|
200
|
+
* The entry struct contains a pointer to a buffer to load the tag into. If this
|
201
|
+
* is NULL or the tag_len is 0 then it won't store the tag there. The tag value will be
|
202
|
+
* NULL-terminated if there available space in the supplied buffer. If the tag is larger
|
203
|
+
* than the supplied buffer then it will be truncated. If the caller sets the last element
|
204
|
+
* in the buffer to '\0' before calling this function and it is not '\0' after the function
|
205
|
+
* returns then the value has been truncated.
|
206
|
+
*
|
207
|
+
* @param reader 'This' pointer
|
208
|
+
* @param file The stream to read the histogram from.
|
209
|
+
* @param entry Contains all of the information from the log line that is not the histogram.
|
210
|
+
* @param histogram Pointer to allocate a histogram to or merge into.
|
211
|
+
* @return Will return 0 on success or an error number if there was some wrong
|
212
|
+
* when reading in the histogram. EOF (-1) will indicate that there are no more
|
213
|
+
* histograms left to be read from 'file'.
|
214
|
+
* HDR_INFLATE_INIT_FAIL or HDR_INFLATE_FAIL if
|
215
|
+
* there was a problem with Gzip. HDR_COMPRESSION_COOKIE_MISMATCH or
|
216
|
+
* HDR_ENCODING_COOKIE_MISMATCH if the cookie values are incorrect.
|
217
|
+
* HDR_LOG_INVALID_VERSION if the log can not be parsed. ENOMEM if buffer space
|
218
|
+
* or the histogram can not be allocated. EIO if there was an error during
|
219
|
+
* the read. EINVAL in any input values are incorrect.
|
220
|
+
*/
|
221
|
+
int hdr_log_read_entry(
|
222
|
+
struct hdr_log_reader* reader, FILE* file, struct hdr_log_entry *entry, struct hdr_histogram** histogram);
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Returns a string representation of the error number.
|
226
|
+
*
|
227
|
+
* @param errnum The error response from a previous call.
|
228
|
+
* @return The user readable representation of the error.
|
229
|
+
*/
|
230
|
+
const char* hdr_strerror(int errnum);
|
231
|
+
|
232
|
+
#ifdef __cplusplus
|
233
|
+
}
|
234
|
+
#endif
|
235
|
+
|
236
|
+
#endif
|
@@ -0,0 +1,171 @@
|
|
1
|
+
/**
|
2
|
+
* hdr_histogram_log.c
|
3
|
+
* Written by Michael Barker and released to the public domain,
|
4
|
+
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <stdint.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <string.h>
|
10
|
+
|
11
|
+
#include "hdr_histogram.h"
|
12
|
+
#include "hdr_histogram_log.h"
|
13
|
+
#include "hdr_tests.h"
|
14
|
+
|
15
|
+
#define UNUSED(x) (void)(x)
|
16
|
+
|
17
|
+
const char* hdr_strerror(int errnum)
|
18
|
+
{
|
19
|
+
switch (errnum)
|
20
|
+
{
|
21
|
+
case HDR_COMPRESSION_COOKIE_MISMATCH:
|
22
|
+
return "Compression cookie mismatch";
|
23
|
+
case HDR_ENCODING_COOKIE_MISMATCH:
|
24
|
+
return "Encoding cookie mismatch";
|
25
|
+
case HDR_DEFLATE_INIT_FAIL:
|
26
|
+
return "Deflate initialisation failed";
|
27
|
+
case HDR_DEFLATE_FAIL:
|
28
|
+
return "Deflate failed";
|
29
|
+
case HDR_INFLATE_INIT_FAIL:
|
30
|
+
return "Inflate initialisation failed";
|
31
|
+
case HDR_INFLATE_FAIL:
|
32
|
+
return "Inflate failed";
|
33
|
+
case HDR_LOG_INVALID_VERSION:
|
34
|
+
return "Log - invalid version in log header";
|
35
|
+
case HDR_TRAILING_ZEROS_INVALID:
|
36
|
+
return "Invalid number of trailing zeros";
|
37
|
+
case HDR_VALUE_TRUNCATED:
|
38
|
+
return "Truncated value found when decoding";
|
39
|
+
case HDR_ENCODED_INPUT_TOO_LONG:
|
40
|
+
return "The encoded input exceeds the size of the histogram";
|
41
|
+
default:
|
42
|
+
return strerror(errnum);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
int hdr_encode_compressed(
|
47
|
+
struct hdr_histogram* h,
|
48
|
+
uint8_t** compressed_histogram,
|
49
|
+
size_t* compressed_len)
|
50
|
+
{
|
51
|
+
UNUSED(h);
|
52
|
+
UNUSED(compressed_histogram);
|
53
|
+
UNUSED(compressed_len);
|
54
|
+
|
55
|
+
return -1;
|
56
|
+
}
|
57
|
+
|
58
|
+
int hdr_decode_compressed(
|
59
|
+
uint8_t* buffer, size_t length, struct hdr_histogram** histogram)
|
60
|
+
{
|
61
|
+
UNUSED(buffer);
|
62
|
+
UNUSED(length);
|
63
|
+
UNUSED(histogram);
|
64
|
+
|
65
|
+
return -1;
|
66
|
+
}
|
67
|
+
|
68
|
+
int hdr_log_writer_init(struct hdr_log_writer* writer)
|
69
|
+
{
|
70
|
+
UNUSED(writer);
|
71
|
+
|
72
|
+
return -1;
|
73
|
+
}
|
74
|
+
|
75
|
+
int hdr_log_write_header(
|
76
|
+
struct hdr_log_writer* writer, FILE* file,
|
77
|
+
const char* user_prefix, hdr_timespec* timestamp)
|
78
|
+
{
|
79
|
+
UNUSED(writer);
|
80
|
+
UNUSED(file);
|
81
|
+
UNUSED(user_prefix);
|
82
|
+
UNUSED(timestamp);
|
83
|
+
|
84
|
+
return -1;
|
85
|
+
}
|
86
|
+
|
87
|
+
int hdr_log_write(
|
88
|
+
struct hdr_log_writer* writer,
|
89
|
+
FILE* file,
|
90
|
+
const hdr_timespec* start_timestamp,
|
91
|
+
const hdr_timespec* end_timestamp,
|
92
|
+
struct hdr_histogram* histogram)
|
93
|
+
{
|
94
|
+
UNUSED(writer);
|
95
|
+
UNUSED(file);
|
96
|
+
UNUSED(start_timestamp);
|
97
|
+
UNUSED(end_timestamp);
|
98
|
+
UNUSED(histogram);
|
99
|
+
|
100
|
+
return -1;
|
101
|
+
}
|
102
|
+
|
103
|
+
int hdr_log_write_entry(
|
104
|
+
struct hdr_log_writer* writer,
|
105
|
+
FILE* file,
|
106
|
+
struct hdr_log_entry* entry,
|
107
|
+
struct hdr_histogram* histogram)
|
108
|
+
{
|
109
|
+
UNUSED(writer);
|
110
|
+
UNUSED(file);
|
111
|
+
UNUSED(entry);
|
112
|
+
UNUSED(histogram);
|
113
|
+
|
114
|
+
return -1;
|
115
|
+
}
|
116
|
+
|
117
|
+
int hdr_log_reader_init(struct hdr_log_reader* reader)
|
118
|
+
{
|
119
|
+
UNUSED(reader);
|
120
|
+
|
121
|
+
return -1;
|
122
|
+
}
|
123
|
+
|
124
|
+
int hdr_log_read_header(struct hdr_log_reader* reader, FILE* file)
|
125
|
+
{
|
126
|
+
UNUSED(reader);
|
127
|
+
UNUSED(file);
|
128
|
+
|
129
|
+
return -1;
|
130
|
+
}
|
131
|
+
|
132
|
+
int hdr_log_read(
|
133
|
+
struct hdr_log_reader* reader, FILE* file, struct hdr_histogram** histogram,
|
134
|
+
hdr_timespec* timestamp, hdr_timespec* interval)
|
135
|
+
{
|
136
|
+
UNUSED(reader);
|
137
|
+
UNUSED(file);
|
138
|
+
UNUSED(histogram);
|
139
|
+
UNUSED(timestamp);
|
140
|
+
UNUSED(interval);
|
141
|
+
|
142
|
+
return -1;
|
143
|
+
}
|
144
|
+
|
145
|
+
int hdr_log_read_entry(
|
146
|
+
struct hdr_log_reader* reader, FILE* file, struct hdr_log_entry *entry, struct hdr_histogram** histogram)
|
147
|
+
{
|
148
|
+
UNUSED(reader);
|
149
|
+
UNUSED(file);
|
150
|
+
UNUSED(entry);
|
151
|
+
UNUSED(histogram);
|
152
|
+
|
153
|
+
return -1;
|
154
|
+
}
|
155
|
+
|
156
|
+
int hdr_log_encode(struct hdr_histogram* histogram, char** encoded_histogram)
|
157
|
+
{
|
158
|
+
UNUSED(histogram);
|
159
|
+
UNUSED(encoded_histogram);
|
160
|
+
|
161
|
+
return -1;
|
162
|
+
}
|
163
|
+
|
164
|
+
int hdr_log_decode(struct hdr_histogram** histogram, char* base64_histogram, size_t base64_len)
|
165
|
+
{
|
166
|
+
UNUSED(histogram);
|
167
|
+
UNUSED(base64_histogram);
|
168
|
+
UNUSED(base64_len);
|
169
|
+
|
170
|
+
return -1;
|
171
|
+
}
|
@@ -0,0 +1,227 @@
|
|
1
|
+
/**
|
2
|
+
* hdr_interval_recorder.h
|
3
|
+
* Written by Michael Barker and released to the public domain,
|
4
|
+
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include "hdr_atomic.h"
|
8
|
+
#include "hdr_interval_recorder.h"
|
9
|
+
|
10
|
+
#ifndef HDR_MALLOC_INCLUDE
|
11
|
+
#define HDR_MALLOC_INCLUDE "hdr_malloc.h"
|
12
|
+
#endif
|
13
|
+
|
14
|
+
#include HDR_MALLOC_INCLUDE
|
15
|
+
|
16
|
+
int hdr_interval_recorder_init(struct hdr_interval_recorder* r)
|
17
|
+
{
|
18
|
+
r->active = r->inactive = NULL;
|
19
|
+
return hdr_writer_reader_phaser_init(&r->phaser);
|
20
|
+
}
|
21
|
+
|
22
|
+
int hdr_interval_recorder_init_all(
|
23
|
+
struct hdr_interval_recorder* r,
|
24
|
+
int64_t lowest_discernible_value,
|
25
|
+
int64_t highest_trackable_value,
|
26
|
+
int significant_figures)
|
27
|
+
{
|
28
|
+
int result;
|
29
|
+
|
30
|
+
r->active = r->inactive = NULL;
|
31
|
+
result = hdr_writer_reader_phaser_init(&r->phaser);
|
32
|
+
result = result == 0
|
33
|
+
? hdr_init(lowest_discernible_value, highest_trackable_value, significant_figures, &r->active)
|
34
|
+
: result;
|
35
|
+
|
36
|
+
return result;
|
37
|
+
}
|
38
|
+
|
39
|
+
void hdr_interval_recorder_destroy(struct hdr_interval_recorder* r)
|
40
|
+
{
|
41
|
+
hdr_writer_reader_phaser_destroy(&r->phaser);
|
42
|
+
if (r->active) {
|
43
|
+
hdr_close(r->active);
|
44
|
+
}
|
45
|
+
if (r->inactive) {
|
46
|
+
hdr_close(r->inactive);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
struct hdr_histogram* hdr_interval_recorder_sample_and_recycle(
|
51
|
+
struct hdr_interval_recorder* r,
|
52
|
+
struct hdr_histogram* histogram_to_recycle)
|
53
|
+
{
|
54
|
+
struct hdr_histogram* old_active;
|
55
|
+
|
56
|
+
if (NULL == histogram_to_recycle)
|
57
|
+
{
|
58
|
+
int64_t lo = r->active->lowest_discernible_value;
|
59
|
+
int64_t hi = r->active->highest_trackable_value;
|
60
|
+
int significant_figures = r->active->significant_figures;
|
61
|
+
hdr_init(lo, hi, significant_figures, &histogram_to_recycle);
|
62
|
+
}
|
63
|
+
else
|
64
|
+
{
|
65
|
+
hdr_reset(histogram_to_recycle);
|
66
|
+
}
|
67
|
+
|
68
|
+
hdr_phaser_reader_lock(&r->phaser);
|
69
|
+
|
70
|
+
/* volatile read */
|
71
|
+
old_active = hdr_atomic_load_pointer(&r->active);
|
72
|
+
|
73
|
+
/* volatile write */
|
74
|
+
hdr_atomic_store_pointer(&r->active, histogram_to_recycle);
|
75
|
+
|
76
|
+
hdr_phaser_flip_phase(&r->phaser, 0);
|
77
|
+
|
78
|
+
hdr_phaser_reader_unlock(&r->phaser);
|
79
|
+
|
80
|
+
return old_active;
|
81
|
+
}
|
82
|
+
|
83
|
+
struct hdr_histogram* hdr_interval_recorder_sample(struct hdr_interval_recorder* r)
|
84
|
+
{
|
85
|
+
r->inactive = hdr_interval_recorder_sample_and_recycle(r, r->inactive);
|
86
|
+
return r->inactive;
|
87
|
+
}
|
88
|
+
|
89
|
+
static void hdr_interval_recorder_update(
|
90
|
+
struct hdr_interval_recorder* r,
|
91
|
+
void(*update_action)(struct hdr_histogram*, void*),
|
92
|
+
void* arg)
|
93
|
+
{
|
94
|
+
int64_t val = hdr_phaser_writer_enter(&r->phaser);
|
95
|
+
|
96
|
+
void* active = hdr_atomic_load_pointer(&r->active);
|
97
|
+
|
98
|
+
update_action(active, arg);
|
99
|
+
|
100
|
+
hdr_phaser_writer_exit(&r->phaser, val);
|
101
|
+
}
|
102
|
+
|
103
|
+
static void update_values(struct hdr_histogram* data, void* arg)
|
104
|
+
{
|
105
|
+
struct hdr_histogram* h = data;
|
106
|
+
int64_t* params = arg;
|
107
|
+
params[2] = hdr_record_values(h, params[0], params[1]);
|
108
|
+
}
|
109
|
+
|
110
|
+
static void update_values_atomic(struct hdr_histogram* data, void* arg)
|
111
|
+
{
|
112
|
+
struct hdr_histogram* h = data;
|
113
|
+
int64_t* params = arg;
|
114
|
+
params[2] = hdr_record_values_atomic(h, params[0], params[1]);
|
115
|
+
}
|
116
|
+
|
117
|
+
int64_t hdr_interval_recorder_record_values(
|
118
|
+
struct hdr_interval_recorder* r,
|
119
|
+
int64_t value,
|
120
|
+
int64_t count
|
121
|
+
)
|
122
|
+
{
|
123
|
+
int64_t params[3];
|
124
|
+
params[0] = value;
|
125
|
+
params[1] = count;
|
126
|
+
params[2] = 0;
|
127
|
+
|
128
|
+
hdr_interval_recorder_update(r, update_values, ¶ms[0]);
|
129
|
+
return params[2];
|
130
|
+
}
|
131
|
+
|
132
|
+
int64_t hdr_interval_recorder_record_value(
|
133
|
+
struct hdr_interval_recorder* r,
|
134
|
+
int64_t value
|
135
|
+
)
|
136
|
+
{
|
137
|
+
return hdr_interval_recorder_record_values(r, value, 1);
|
138
|
+
}
|
139
|
+
|
140
|
+
static void update_corrected_values(struct hdr_histogram* data, void* arg)
|
141
|
+
{
|
142
|
+
struct hdr_histogram* h = data;
|
143
|
+
int64_t* params = arg;
|
144
|
+
params[3] = hdr_record_corrected_values(h, params[0], params[1], params[2]);
|
145
|
+
}
|
146
|
+
|
147
|
+
static void update_corrected_values_atomic(struct hdr_histogram* data, void* arg)
|
148
|
+
{
|
149
|
+
struct hdr_histogram* h = data;
|
150
|
+
int64_t* params = arg;
|
151
|
+
params[3] = hdr_record_corrected_values_atomic(h, params[0], params[1], params[2]);
|
152
|
+
}
|
153
|
+
|
154
|
+
int64_t hdr_interval_recorder_record_corrected_values(
|
155
|
+
struct hdr_interval_recorder* r,
|
156
|
+
int64_t value,
|
157
|
+
int64_t count,
|
158
|
+
int64_t expected_interval
|
159
|
+
)
|
160
|
+
{
|
161
|
+
int64_t params[4];
|
162
|
+
params[0] = value;
|
163
|
+
params[1] = count;
|
164
|
+
params[2] = expected_interval;
|
165
|
+
params[3] = 0;
|
166
|
+
|
167
|
+
hdr_interval_recorder_update(r, update_corrected_values, ¶ms[0]);
|
168
|
+
return params[3];
|
169
|
+
}
|
170
|
+
|
171
|
+
int64_t hdr_interval_recorder_record_corrected_value(
|
172
|
+
struct hdr_interval_recorder* r,
|
173
|
+
int64_t value,
|
174
|
+
int64_t expected_interval
|
175
|
+
)
|
176
|
+
{
|
177
|
+
return hdr_interval_recorder_record_corrected_values(r, value, 1, expected_interval);
|
178
|
+
}
|
179
|
+
|
180
|
+
int64_t hdr_interval_recorder_record_value_atomic(
|
181
|
+
struct hdr_interval_recorder* r,
|
182
|
+
int64_t value
|
183
|
+
)
|
184
|
+
{
|
185
|
+
return hdr_interval_recorder_record_values_atomic(r, value, 1);
|
186
|
+
}
|
187
|
+
|
188
|
+
int64_t hdr_interval_recorder_record_values_atomic(
|
189
|
+
struct hdr_interval_recorder* r,
|
190
|
+
int64_t value,
|
191
|
+
int64_t count
|
192
|
+
)
|
193
|
+
{
|
194
|
+
int64_t params[3];
|
195
|
+
params[0] = value;
|
196
|
+
params[1] = count;
|
197
|
+
params[2] = 0;
|
198
|
+
|
199
|
+
hdr_interval_recorder_update(r, update_values_atomic, ¶ms[0]);
|
200
|
+
return params[2];
|
201
|
+
}
|
202
|
+
|
203
|
+
int64_t hdr_interval_recorder_record_corrected_value_atomic(
|
204
|
+
struct hdr_interval_recorder* r,
|
205
|
+
int64_t value,
|
206
|
+
int64_t expected_interval
|
207
|
+
)
|
208
|
+
{
|
209
|
+
return hdr_interval_recorder_record_corrected_values_atomic(r, value, 1, expected_interval);
|
210
|
+
}
|
211
|
+
|
212
|
+
int64_t hdr_interval_recorder_record_corrected_values_atomic(
|
213
|
+
struct hdr_interval_recorder* r,
|
214
|
+
int64_t value,
|
215
|
+
int64_t count,
|
216
|
+
int64_t expected_interval
|
217
|
+
)
|
218
|
+
{
|
219
|
+
int64_t params[4];
|
220
|
+
params[0] = value;
|
221
|
+
params[1] = count;
|
222
|
+
params[2] = expected_interval;
|
223
|
+
params[3] = 0;
|
224
|
+
|
225
|
+
hdr_interval_recorder_update(r, update_corrected_values_atomic, ¶ms[0]);
|
226
|
+
return params[3];
|
227
|
+
}
|