Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cbuilder: :set_instance_option() may duplicate an instance #404

Open
Totktonada opened this issue Nov 29, 2024 · 0 comments
Open

cbuilder: :set_instance_option() may duplicate an instance #404

Totktonada opened this issue Nov 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Totktonada
Copy link
Member

#!/usr/bin/env tarantool

local yaml = require('yaml')
local cbuilder = require('luatest.cbuilder')

local config_1 = cbuilder:new()
    :use_replicaset('r-001')
    :add_instance('i-001', {})
    :set_instance_option('i-001', 'replication.timeout', 0.1)
    :config()
print(yaml.encode(config_1))
--[[
---
groups:
  group-001:
    replicasets:
      r-001:
        instances:
          i-001:              # !! (just one)
            replication:
              timeout: 0.1
credentials:
  users:
    replicator:
      password: secret
      roles:
      - replication
    client:
      password: secret
      roles:
      - super
iproto:
  listen:
  - uri: unix/:./{{ instance_name }}.iproto
  advertise:
    peer:
      login: replicator
replication:
  timeout: 0.1
...
]]--

local config_2 = cbuilder:new(config_1)
    -- I forgot to write :use_replicaset('r-001') here
    :set_instance_option('i-001', 'replication.timeout', 1000)
    :config()
print(yaml.encode(config_2))
--[[
---
groups:
  group-001:
    replicasets:
      replicaset-001:
        instances:
          i-001:              # !! (duplicate)
            replication:
              timeout: 1000
      r-001:
        instances:
          i-001:              # !! (initial)
            replication:
              timeout: 0.1
credentials:
  users:
    replicator:
      password: secret
      roles:
      - replication
    client:
      password: secret
      roles:
      - super
iproto:
  listen:
  - uri: unix/:./{{ instance_name }}.iproto
  advertise:
    peer:
      login: replicator
replication:
  timeout: 0.1
...
]]--

So, now we have to add :use_replicaset('r-001'), when updating the configuration.

Since the instance name is unique across a cluster1, we can find the given instance across all groups/replicasets instead of assuming default ones group-001 and replicaset-001. At least, if an explicit :use_group() and/or :use_replicaset() are not given.

If the instance is not found, raise an error instead of creating it, because there is a designated :add_instance() function.

Footnotes

  1. https://github.com/tarantool/tarantool/issues/10347

@Totktonada Totktonada added the bug Something isn't working label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant