Skip to content

Commit

Permalink
draft: vshard.topology retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Grubov committed Feb 26, 2024
1 parent 687b01a commit a9b0ae8
Show file tree
Hide file tree
Showing 9 changed files with 458 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ["1.10.15", "2.8.4", "2.10.6", "2.10.7-gc64-amd64", "2.11.0", "2.11.1"]
version: ["1.10.15", "2.8.4", "2.10.6", "2.10.7-gc64-amd64", "2.11.0", "2.11.1", "2.11.2"]
steps:
- uses: actions/checkout@master
- uses: docker/setup-buildx-action@v2
Expand Down
66 changes: 65 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local yaml = require 'yaml'.new()
local digest = require 'digest'
local fiber = require 'fiber'
local clock = require 'clock'
local uri = require 'uri'
json.cfg{ encode_invalid_as_nil = true }
yaml.cfg{ encode_use_tostring = true }

Expand Down Expand Up @@ -590,6 +591,11 @@ local function etcd_load( M, etcd_conf, local_cfg )
etcd:discovery()

local all_cfg = etcd:get_all()

function M.etcd.get_all_cached()
return all_cfg
end

if etcd_conf.print_config then
print("Loaded config from etcd",yaml.encode(all_cfg))
end
Expand All @@ -599,7 +605,9 @@ local function etcd_load( M, etcd_conf, local_cfg )
local instance_cfg = all_instances_cfg[instance_name]
assert(instance_cfg,"Instance name "..instance_name.." is not known to etcd")

local all_clusters_cfg = all_cfg.clusters or all_cfg.shards
all_cfg.clusters = all_cfg.clusters or all_cfg.shards
all_cfg.shards = nil
local all_clusters_cfg = all_cfg.clusters

local master_selection_policy
local cluster_cfg
Expand Down Expand Up @@ -810,6 +818,62 @@ local M
}
end,
_load_cfg = load_cfg,
sharding = function()
local all_cfg = M.etcd.get_all_cached()

-- common vshard cfg
local cfg = table.deepcopy(all_cfg.common.vshard or {})

local creds = M.get('credentials.sharding', {})
if type(creds) ~= 'table' then
creds = {}
end
-- default sharding creds are guest:""
creds.login = creds.login or 'guest'
creds.password = creds.password or ''

local rebalancer_name = cfg.rebalancer
cfg.rebalancer = nil

local sharding = {}
-- construct sharding table
for rs_name, replicaset in pairs(all_cfg.clusters) do
local replicas = {}
for instance_name, instance in pairs(all_cfg.instances) do
if instance.cluster == rs_name then
local remote = assert(uri.parse(instance.box.remote_addr or instance.box.listen))
remote.login = creds.login
remote.password = creds.password
local replica_zone = nil
if type(instance.vshard) == 'table' then
replica_zone = instance.vshard.zone -- can be nil
end
replicas[instance.box.instance_uuid] = {
name = instance_name,
uuid = instance.box.uuid,
uri = uri.format(remote, true),
master = replicaset.master == instance_name,
zone = replica_zone,
}
end
end
local rs = {}
rs.replicas = replicas
if type(replicaset.vshard) == 'table' then
rs.weight = replicaset.vshard.weight
rs.lock = replicaset.vshard.lock
end

if rebalancer_name then
rs.rebalancer = rebalancer_name == rs_name
end

sharding[replicaset.replicaset_uuid] = rs
end

-- all other fields from common/vshard are left without any changes
return sharding
end,
},{
---Reinitiates moonlibs.config
---@param args moonlibs.config.opts
Expand Down
2 changes: 1 addition & 1 deletion run_test_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
pwd
rm -rf /root/.cache/
cp -ar /root/.rocks /source/config/
/source/config/.rocks/bin/luatest --coverage -v spec/
/source/config/.rocks/bin/luatest --coverage -vv spec/
1 change: 0 additions & 1 deletion spec/01_single_test.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local t = require 'luatest' --[[@as luatest]]
local uri = require 'uri'

---@class test.config.single:luatest.group
local g = t.group('single', {
Expand Down
Loading

0 comments on commit a9b0ae8

Please sign in to comment.