Skip to content

Commit

Permalink
[feature](selectdb-cloud) Add cloud cluster name in FE auditlog (apac…
Browse files Browse the repository at this point in the history
…he#832)

Also, change some config variable names of file cache.
  • Loading branch information
Lchangliang authored Oct 13, 2022
1 parent 25324ca commit e1d0179
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,8 @@ CONF_Bool(enable_file_cache, "false");
// format: [{"path":"/mnt/disk3/selectdb_cloud/file_cache","normal":20,"persistent":10}]
CONF_String(file_cache_path, "");
CONF_String(disposable_file_cache_path, "");
CONF_Int64(max_file_segment_size, "1048576");
CONF_Int64(max_elements, "0");
CONF_Int64(file_cache_max_file_segment_size, "1048576");
CONF_Int64(file_cache_max_elements, "0");
CONF_Bool(clear_file_cache, "false");
CONF_Bool(enable_query_cache_limit, "false");

Expand Down
9 changes: 5 additions & 4 deletions be/src/io/cloud/cached_remote_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ std::pair<size_t, size_t> CachedRemoteFileReader::_align_size(size_t offset,
size_t read_size) const {
size_t left = offset;
size_t right = offset + read_size - 1;
size_t align_left = (left / config::max_file_segment_size) * config::max_file_segment_size;
size_t align_right =
(right / config::max_file_segment_size + 1) * config::max_file_segment_size;
size_t align_left = (left / config::file_cache_max_file_segment_size) *
config::file_cache_max_file_segment_size;
size_t align_right = (right / config::file_cache_max_file_segment_size + 1) *
config::file_cache_max_file_segment_size;
align_right = align_right < size() ? align_right : size();
size_t align_size = align_right - align_left;
return std::make_pair(align_left, align_size);
Expand Down Expand Up @@ -98,7 +99,7 @@ Status CachedRemoteFileReader::read_at_impl(size_t offset, Slice result, size_t*
ReadStatistics stats;
stats.bytes_read = bytes_req;
auto [align_left, align_size] = _align_size(offset, bytes_req);
DCHECK((align_left % config::max_file_segment_size) == 0);
DCHECK((align_left % config::file_cache_max_file_segment_size) == 0);
// if state == nullptr, the method is called for read footer/index
bool is_persistent = state ? state->is_persistent : true;
TUniqueId query_id = state && state->query_id ? *state->query_id : TUniqueId();
Expand Down
6 changes: 3 additions & 3 deletions be/src/olap/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ io::FileCacheSettings CachePath::init_settings() const {
io::FileCacheSettings settings;
settings.max_size = normal_bytes;
settings.persistent_max_size = persistent_bytes;
settings.max_elements =
config::max_elements == 0 ? settings.max_elements : config::max_elements;
settings.max_elements = config::file_cache_max_elements == 0 ? settings.max_elements
: config::file_cache_max_elements;
settings.persistent_max_elements = settings.max_elements;
settings.max_query_cache_size = query_limit_bytes;
settings.max_file_segment_size = config::max_file_segment_size;
settings.max_file_segment_size = config::file_cache_max_file_segment_size;
return settings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public enum EventType {
public long peakMemoryBytes = -1;
@AuditField(value = "SqlDigest")
public String sqlDigest = "";
@AuditField(value = "cloudClusterName")
public String cloudClusterName = "";

@AuditField(value = "TraceId")
public String traceId = "";
Expand Down Expand Up @@ -126,6 +128,11 @@ public AuditEventBuilder setDb(String db) {
return this;
}

public AuditEventBuilder setCloudCluster(String cloudClusterName) {
auditEvent.cloudClusterName = cloudClusterName;
return this;
}

public AuditEventBuilder setState(String state) {
auditEvent.state = state;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ private void auditAfterExec(String origStmt, StatementBase parsedStmt, Data.PQue
.setReturnRows(ctx.getReturnRows())
.setStmtId(ctx.getStmtId())
.setQueryId(ctx.queryId() == null ? "NaN" : DebugUtil.printId(ctx.queryId()))
.setTraceId(spanContext.isValid() ? spanContext.getTraceId() : "");
.setTraceId(spanContext.isValid() ? spanContext.getTraceId() : "")
.setCloudCluster(!Config.cloud_unique_id.isEmpty() && ctx.cloudCluster != null
? ctx.cloudCluster : "UNKNOWN");


if (ctx.getState().isQuery()) {
MetricRepo.COUNTER_QUERY_ALL.increase(1L);
Expand Down

0 comments on commit e1d0179

Please sign in to comment.