Skip to content

Commit

Permalink
Merge branch 'main' of github.com:infiniflow/infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
cike8899 committed Nov 7, 2024
2 parents 2c82015 + 0b68b43 commit d1080d3
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 26 deletions.
24 changes: 23 additions & 1 deletion python/infinity_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,31 @@ def show_node(self, node_name):
h = self.net.set_up_header(["accept"])
r = self.net.request(url, "get", h, {})
self.net.raise_exception(r)
print(r.json())
# print(r.json())
return database_result(node_name=r.json()["node"]["name"], node_role=r.json()["node"]["role"], node_status=r.json()["node"]["status"])

def show_global_variables(self):
url = "variables/global"
h = self.net.set_up_header(["accept"])
r = self.net.request(url, "get", h, {})
self.net.raise_exception(r)
return r.json()

def show_global_variable(self, var_name: str):
url = f"variables/global/{var_name}"
h = self.net.set_up_header(["accept"])
r = self.net.request(url, "get", h, {})
self.net.raise_exception(r)
return r.json()

def set_config(self, config: dict):
url = "configs"
h = self.net.set_up_header(["accept", "content-type"])
d = self.net.set_up_data([], config)
r = self.net.request(url, "post", h, d)
self.net.raise_exception(r)
return database_result()

####################3####################3####################3####################3####################3####################3####################3####################3

class database_http:
Expand Down
2 changes: 1 addition & 1 deletion python/test_pysdk/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def skip_if_local_infinity(request):

@pytest.fixture(scope="function")
def skip_if_remote_infinity(request):
if not request.config.getoption("--local-infinity"):
if not request.config.getoption("--local-infinity") and not request.config.getoption("--http"):
pytest.skip("Skipping remote-infinity test")

@pytest.fixture(scope="function")
Expand Down
45 changes: 45 additions & 0 deletions python/test_pysdk/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,48 @@ def test_show(self, suffix):
self._test_show_table(suffix)
self._test_show_columns(suffix)
self._test_show_big_databases(suffix)

@pytest.mark.usefixtures("skip_if_local_infinity")
@pytest.mark.usefixtures("skip_if_remote_infinity")
# @pytest.mark.skip(reason="Cannot show follower number")
def test_show_global_variables(self, suffix):
vars = self.infinity_obj.show_global_variables()
print(vars)

@pytest.mark.usefixtures("skip_if_local_infinity")
@pytest.mark.usefixtures("skip_if_remote_infinity")
def test_show_global_variable(self, suffix):
var: dict = self.infinity_obj.show_global_variable("cache_result_capacity")
assert var["error_code"] == ErrorCode.OK
assert "cache_result_capacity" in var

var = self.infinity_obj.show_global_variable("cache_result_num")
assert var["error_code"] == ErrorCode.OK
assert "cache_result_num" in var

var = self.infinity_obj.show_global_variable("result_cache")
assert var["error_code"] == ErrorCode.OK
assert "result_cache" in var

try:
var = self.infinity_obj.show_global_variable("invalid_variable")
except Exception as e:
assert e.error_code == ErrorCode.NO_SUCH_SYSTEM_VAR
else:
raise Exception("Should raise exception")

@pytest.mark.usefixtures("skip_if_local_infinity")
@pytest.mark.usefixtures("skip_if_remote_infinity")
def test_set_config(self, suffix):
res = self.infinity_obj.set_config({"cache_result_capacity": 100})
assert res.error_code == ErrorCode.OK

res = self.infinity_obj.set_config({"result_cache": "clear"})
assert res.error_code == ErrorCode.OK

try:
res = self.infinity_obj.set_config({"invalid_variable": "value"})
except Exception as e:
assert e.error_code == ErrorCode.INVALID_COMMAND
else:
raise Exception("Should raise exception")
47 changes: 27 additions & 20 deletions src/executor/operator/physical_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,50 +145,57 @@ bool PhysicalCommand::Execute(QueryContext *query_context, OperatorState *operat
GlobalOptionIndex config_index = config->GetOptionIndex(set_command->var_name());
switch(config_index) {
case GlobalOptionIndex::kResultCache: {
ResultCacheManager *cache_mgr = query_context->storage()->GetResultCacheManagerPtr();
const String &result_cache_status = config->ResultCache();
if (set_command->value_type() == SetVarType::kInteger) {
if (result_cache_status == "off") {
Status status = Status::InvalidCommand(fmt::format("Result cache manager is off"));
RecoverableError(status);
}
i64 cache_num = set_command->value_int();
if (cache_num < 0) {
Status status = Status::InvalidCommand(fmt::format("Attempt to set cache result num: {}", cache_num));
RecoverableError(status);
}
cache_mgr->ResetCacheNumCapacity(cache_num);
break;
}
if (set_command->value_type() != SetVarType::kString) {
Status status = Status::DataTypeMismatch("String", set_command->value_type_str());
RecoverableError(status);
}
if (result_cache_status == "off" && set_command->value_str() != "on") {
String cmd = set_command->value_str();
ResultCacheManager *cache_mgr = query_context->storage()->GetResultCacheManagerPtr();
const String &result_cache_status = config->ResultCache();
if (result_cache_status == "off" && cmd != "on") {
Status status = Status::InvalidCommand(fmt::format("Result cache manager is off"));
RecoverableError(status);
}
if (set_command->value_str() == "on") {
if (cmd == "on") {
config->SetCacheResult("on");
return true;
}
if (set_command->value_str() == "off") {
if (cmd == "off") {
cache_mgr->ClearCache();
config->SetCacheResult("off");
return true;
}
if (set_command->value_str() == "suspend") {
if (cmd == "suspend") {
config->SetCacheResult("suspend");
return true;
}
if (set_command->value_str() == "clear") {
if (cmd == "clear") {
cache_mgr->ClearCache();
return true;
}
Status status = Status::SetInvalidVarValue("cache result", "on, off");
RecoverableError(status);
break;
}
case GlobalOptionIndex::kCacheResultCapacity: {
if (set_command->value_type() != SetVarType::kInteger) {
Status status = Status::DataTypeMismatch("Integer", set_command->value_type_str());
RecoverableError(status);
}
i64 cache_num = set_command->value_int();
ResultCacheManager *cache_mgr = query_context->storage()->GetResultCacheManagerPtr();
const String &result_cache_status = config->ResultCache();
if (result_cache_status == "off") {
Status status = Status::InvalidCommand(fmt::format("Result cache manager is off"));
RecoverableError(status);
}
if (cache_num < 0) {
Status status = Status::InvalidCommand(fmt::format("Attempt to set cache result num: {}", cache_num));
RecoverableError(status);
}
cache_mgr->ResetCacheNumCapacity(cache_num);
break;
}
case GlobalOptionIndex::kLogLevel: {
if (set_command->value_type() != SetVarType::kString) {
Status status = Status::DataTypeMismatch("String", set_command->value_type_str());
Expand Down
27 changes: 27 additions & 0 deletions src/executor/operator/physical_show.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4426,6 +4426,33 @@ void PhysicalShow::ExecuteShowGlobalVariables(QueryContext *query_context, ShowO
ValueExpression value_expr(value);
value_expr.AppendToChunk(output_block_ptr->column_vectors[1]);
}
{
// option description
Value value = Value::MakeVarchar("Result cache capacity");
ValueExpression value_expr(value);
value_expr.AppendToChunk(output_block_ptr->column_vectors[2]);
}
break;
}
case GlobalVariable::kCacheResultNum: {
const String &result_cache_status = config->ResultCache();
if (result_cache_status == "off") {
break;
}
ResultCacheManager *cache_mgr = query_context->storage()->GetResultCacheManagerPtr();
SizeT cache_num_used = cache_mgr->cache_num_used();
{
// option name
Value value = Value::MakeVarchar(var_name);
ValueExpression value_expr(value);
value_expr.AppendToChunk(output_block_ptr->column_vectors[0]);
}
{
// option value
Value value = Value::MakeVarchar(std::to_string(cache_num_used));
ValueExpression value_expr(value);
value_expr.AppendToChunk(output_block_ptr->column_vectors[1]);
}
{
// option description
Value value = Value::MakeVarchar("Result cache num");
Expand Down
7 changes: 6 additions & 1 deletion src/main/cluster_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ ClusterManager::~ClusterManager() {

void ClusterManager::InitAsAdmin() { current_node_role_ = NodeRole::kAdmin; }

void ClusterManager::InitAsStandalone() { current_node_role_ = NodeRole::kStandalone; }
void ClusterManager::InitAsStandalone() {
this_node_ = MakeShared<NodeInfo>();
this_node_->node_role_ = NodeRole::kStandalone;
this_node_->node_status_ = NodeStatus::kAlive;
current_node_role_ = NodeRole::kStandalone;
}

Status ClusterManager::InitAsLeader(const String &node_name) {

Expand Down
6 changes: 3 additions & 3 deletions test/sql/config/cache_config.slt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ statement ok
SET CONFIG result_cache "on";

statement ok
SET CONFIG result_cache 1;
SET CONFIG cache_result_capacity 1;

query I
SHOW GLOBAL VARIABLE cache_result_capacity;
Expand Down Expand Up @@ -121,13 +121,13 @@ statement error
SHOW GLOBAL VARIABLE cache_result_capacity;

statement error
SET CONFIG result_cache 10000;
SET CONFIG cache_result_capacity 10000;

statement ok
SET CONFIG result_cache "on";

statement ok
SET CONFIG result_cache 10000;
SET CONFIG cache_result_capacity 10000;

query I
SHOW GLOBAL VARIABLE cache_result_num;
Expand Down

0 comments on commit d1080d3

Please sign in to comment.