-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathduckherder_extension_instance_state.hpp
More file actions
61 lines (45 loc) · 1.88 KB
/
Copy pathduckherder_extension_instance_state.hpp
File metadata and controls
61 lines (45 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Per-instance state for duckherder extension.
// State is stored in DuckDB's ObjectCache for automatic cleanup when DatabaseInstance is destroyed.
#pragma once
#include <mutex>
#include "duckdb/common/shared_ptr.hpp"
#include "duckdb/common/string.hpp"
#include "duckdb/storage/object_cache.hpp"
#include "base_query_recorder.hpp"
namespace duckdb {
// Forward declaration.
class ClientContext;
class DatabaseInstance;
//===--------------------------------------------------------------------===//
// Main per-instance state container
// Inherits from ObjectCacheEntry for automatic cleanup when DatabaseInstance is destroyed
//===--------------------------------------------------------------------===//
struct DuckherderInstanceState : public ObjectCacheEntry {
static constexpr const char *OBJECT_TYPE = "DuckherderInstanceState";
static constexpr const char *CACHE_KEY = "duckherder_instance_state";
DuckherderInstanceState();
// Get the current query recorder.
shared_ptr<BaseQueryRecorder> GetQueryRecorder() const;
// ObjectCacheEntry interface
string GetObjectType() override {
return OBJECT_TYPE;
}
static string ObjectType() {
return OBJECT_TYPE;
}
optional_idx GetEstimatedCacheMemory() const override {
return optional_idx {};
}
private:
mutable std::mutex mu;
shared_ptr<BaseQueryRecorder> query_recorder;
};
//===--------------------------------------------------------------------===//
// Helper functions to access instance state
//===--------------------------------------------------------------------===//
// Store instance state in DatabaseInstance
void SetInstanceState(DatabaseInstance &instance, shared_ptr<DuckherderInstanceState> state);
// Get instance state, throwing if not found
DuckherderInstanceState &GetInstanceStateOrThrow(ClientContext &client_context);
DuckherderInstanceState &GetInstanceStateOrThrow(DatabaseInstance &instance);
} // namespace duckdb