From 6cfb54f746deef831727e69f539a29b46ed60cb9 Mon Sep 17 00:00:00 2001
From: Mergen Imeev <imeevma@tarantool.org>
Date: Tue, 22 Aug 2023 15:43:44 +0300
Subject: [PATCH] config: introduce example for sharding

Follow-up #9007

NO_DOC=Will be described when full support for vshard is introduced.
NO_CHANGELOG=Addition of an example.
---
 doc/examples/config/sharding.yaml             | 76 +++++++++++++++++++
 .../cluster_config_schema_test.lua            |  8 ++
 2 files changed, 84 insertions(+)
 create mode 100644 doc/examples/config/sharding.yaml

diff --git a/doc/examples/config/sharding.yaml b/doc/examples/config/sharding.yaml
new file mode 100644
index 0000000000..a74cb41af8
--- /dev/null
+++ b/doc/examples/config/sharding.yaml
@@ -0,0 +1,76 @@
+# See the vshard documentation for proper usage of vshard. The basic scenario
+# with this configuration is described below.
+#
+# Before using sharding, you need to create a spaces that will contain data and
+# define functions to work with these spaces on the storage masters, for
+# example:
+#
+# format = {{'id', 'unsigned'}, {'bucket_id', 'unsigned'}}
+# s = box.schema.space.create('test', {format = format})
+# s:create_index('id', {parts = {'id'}})
+# s:create_index('bucket_id', {parts = {'bucket_id'}, unique = false})
+
+# function get(id) return box.space.test:get(id) end
+# box.schema.func.create('get')
+# box.schema.role.grant('public', 'execute', 'function', 'get')
+
+# function put(id, b_id) box.space.test:insert({id, b_id}) return true end
+# box.schema.func.create('put')
+# box.schema.role.grant('public', 'execute', 'function', 'put')
+#
+# After this you need to call vshard.router.bootstrap() on router.
+#
+# To insert following function can be used on router after bootstrap:
+# vshard.router.call(bucket_id, 'write', 'put', {id, bucket_id})
+#
+# To get data following function can be used on router after bootstrap:
+# vshard.router.call(bucket_id, 'read', 'get', {id})
+
+credentials:
+  users:
+    replicator:
+      password: 'topsecret'
+      roles: [replication]
+     # For now, vshard itself will grant the specified user all the permissions
+     # it needs to prepare instances for sharding. However, they will be revoked
+     # after reload(). Since there is no way to grant the user  the proper
+     # rights to the functions, the "super" role is used.
+    storage:
+      password: 'secret'
+      roles: [super]
+
+iproto:
+  listen: 'unix/:./{{ instance_name }}.iproto'
+  # We currently need to manually define the user for vshard. If the user is not
+  # defined, the guest is used.
+  advertise:
+    peer: replicator@
+    sharding: storage@
+
+sharding:
+  bucket_count: 10000
+
+groups:
+  storages:
+    replication:
+      failover: manual
+    sharding:
+      roles: [storage]
+    replicasets:
+      storages-001:
+        leader: storage-001
+        instances:
+          storage-001: {}
+          storage-002: {}
+      storages-002:
+        leader: storage-004
+        instances:
+          storage-003: {}
+          storage-004: {}
+  routers:
+    replicasets:
+      routers-001:
+        sharding:
+          roles: [router]
+        instances:
+          router-001: {}
diff --git a/test/config-luatest/cluster_config_schema_test.lua b/test/config-luatest/cluster_config_schema_test.lua
index 05ba91faa0..7e655c83e4 100644
--- a/test/config-luatest/cluster_config_schema_test.lua
+++ b/test/config-luatest/cluster_config_schema_test.lua
@@ -291,3 +291,11 @@ g.test_example_replicaset = function()
     fh:close()
     cluster_config:validate(config)
 end
+
+g.test_example_sharding = function()
+    local config_file = fio.abspath('doc/examples/config/sharding.yaml')
+    local fh = fio.open(config_file, {'O_RDONLY'})
+    local config = yaml.decode(fh:read())
+    fh:close()
+    cluster_config:validate(config)
+end
-- 
GitLab