@@ -44,8 +44,10 @@ It also provides the `crud-storage` and `crud-router` roles for
44
44
- [ Read view select conditions] ( #read-view-select-conditions )
45
45
- [ Read view pairs] ( #read-view-pairs )
46
46
- [ Schema] ( #schema )
47
- - [ Cartridge roles] ( #cartridge -roles )
47
+ - [ Tarantool 3 roles] ( #tarantool-3 -roles )
48
48
- [ Usage] ( #usage )
49
+ - [ Cartridge roles] ( #cartridge-roles )
50
+ - [ Usage] ( #usage-1 )
49
51
- [ License] ( #license )
50
52
51
53
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -54,38 +56,84 @@ It also provides the `crud-storage` and `crud-router` roles for
54
56
55
57
First, [ install Tarantool] ( https://www.tarantool.io/en/download ) .
56
58
57
- Now you have the following options for learning the crud API and using it in a
58
- project:
59
-
60
- * Play with crud on a test dataset on a single instance:
61
-
62
- ``` shell
63
- $ git clone https://github.com/tarantool/crud.git
64
- $ cd crud
65
- $ tt rocks make
66
- $ ./doc/playground.lua
67
- tarantool> crud.select(' customers' , {{' <=' , ' age' , 35}}, {first = 10})
68
- tarantool> crud.select(' developers' , nil, {first = 6})
69
- ```
70
- * Install crud into the current directory:
71
-
72
- ``` shell
73
- $ tt rocks install crud
74
- ```
75
- * Add the [ crud initialization code] ( #API ) to router and storage instances
76
- initialization code for [ VShard] ( https://github.com/tarantool/vshard ) .
77
- * Add crud into dependencies of a Cartridge application and add crud roles into
78
- dependencies of your roles (see [ Cartridge roles] ( #cartridge-roles ) section).
79
- * Add crud into dependencies of your application (rockspec, RPM spec -- depends
80
- on your choice) and call crud initialization code from storage and router
81
- code (see [ API] ( #api ) section).
59
+ ### Install
60
+
61
+ #### Manual install
62
+
63
+ To try ` crud ` in your application, you may install it manually fron web
64
+ with ` tt rocks ` rock management tool.
65
+
66
+ ``` bash
67
+ tt rocks install crud
68
+ ```
69
+
70
+ #### Application dependency
71
+
72
+ To use crud in your application, set it as a rockspec dependency.
73
+
74
+ ``` lua
75
+ package = ' myapp'
76
+
77
+ version = ' scm-1'
78
+
79
+ source = {
80
+ url = ' /dev/null' ,
81
+ }
82
+
83
+ dependencies = {
84
+ ' tarantool >= 3.1.0' ,
85
+ ' crud >= <the-latest-tag>-1' ,
86
+ }
87
+
88
+ build = {
89
+ type = ' none' ;
90
+ }
91
+ ```
92
+
93
+ #### Repository clone
94
+
95
+ You can also clone the repository to explore crud and try it inside a sandbox.
96
+
97
+ ``` bash
98
+ git clone https://github.com/tarantool/crud.git
99
+ cd crud
100
+ tt rocks make
101
+ ```
102
+
103
+ ### Usage
104
+
105
+ For Tarantool 3.x, enable crud roles on your application instances in a configuration
106
+ (see [ Tarantool 3 roles] ( #tarantool-3-roles ) section).
107
+ Roles support Tarantool 3.0.2, Tarantool 3.1.0 and newer.
108
+ Older versions are not supported due to
109
+ [ tarantool/tarantool #9643 ] ( https://github.com/tarantool/tarantool/issues/9643 ) and
110
+ [ tarantool/tarantool #9649 ] ( https://github.com/tarantool/tarantool/issues/9649 )
111
+ issues.
112
+
113
+ For Tarantool 1.10 and 2.x, add crud roles into dependencies of your roles
114
+ (see [ Cartridge roles] ( #cartridge-roles ) section).
115
+
116
+ For Tarantool 1.10, 2.x and 3.x you can also manually call
117
+ the [ crud initialization code] ( #API ) on [ VShard] ( https://github.com/tarantool/vshard )
118
+ router and storage instances.
119
+
120
+ ### Sandbox
121
+
122
+ The repository provide a simple sandbox application with a test dataset on a single instance.
123
+
124
+ ``` bash
125
+ ./doc/playground.lua
126
+ tarantool> crud.select(' customers' , {{' <=' , ' age' , 35}}, {first = 10})
127
+ tarantool> crud.select(' developers' , nil, {first = 6})
128
+ ```
82
129
83
130
## API
84
131
85
132
The CRUD operations should be called from router.
86
133
87
134
All VShard storages should call ` crud.init_storage() ` after
88
- ` vshard.storage.cfg() ` (or enable the ` crud-storage ` role for Cartridge)
135
+ ` vshard.storage.cfg() ` (or enable the ` roles.crud-storage ` role for Tarantool 3
136
+ or the ` crud-storage ` role for Cartridge)
89
137
first to initialize storage-side functions that are used to manipulate data
90
138
across the cluster. The storage-side functions have the same access
91
139
as a user calling ` crud.init_storage() ` . Therefore, if ` crud ` do not have
@@ -98,7 +146,8 @@ asynchronous bootstrap is used for Tarantool 3.x and
98
146
synchronous bootstrap is used for Tarantool 1.10 and 2.x.
99
147
100
148
All VShard routers should call ` crud.init_router() ` after ` vshard.router.cfg() `
101
- (or enable the ` crud-router ` role for Cartridge) to make ` crud ` functions
149
+ (or enable the ` roles.crud-storage ` role for Tarantool 3
150
+ or the ` crud-router ` role for Cartridge) to make ` crud ` functions
102
151
callable via ` net.box ` . If a user is allowed to execute ` crud ` functions on
103
152
the router-side then the user does not need additional access on storages.
104
153
@@ -1833,6 +1882,194 @@ crud.schema()
1833
1882
indexes : ...
1834
1883
```
1835
1884
1885
+ ## Tarantool 3 roles
1886
+
1887
+ ` roles.crud-storage ` is a Tarantool 3 role that initializes functions that
1888
+ are used on the storage side to perform CRUD operations. Role must be enabled
1889
+ on sharding storages.
1890
+
1891
+ ` cartridge.roles.crud-router ` is a role that exposes public ` crud ` functions
1892
+ to the global scope so that you can call them via ` net.box ` or with connectors.
1893
+ Role must be enabled on sharding routers.
1894
+
1895
+ Roles support Tarantool 3.0.2, Tarantool 3.1.0 and newer.
1896
+ Older versions are not supported due to
1897
+ [ tarantool/tarantool #9643 ] ( https://github.com/tarantool/tarantool/issues/9643 ) and
1898
+ [ tarantool/tarantool #9649 ] ( https://github.com/tarantool/tarantool/issues/9649 )
1899
+ issues.
1900
+
1901
+ ### Usage
1902
+
1903
+ 1 . Add ` crud ` to dependencies in the project rockspec.
1904
+
1905
+ ** Note** : it's better to use tagged version than ` scm-1 ` .
1906
+ Check the latest available [ release] ( https://github.com/tarantool/crud/releases ) tag and use it.
1907
+
1908
+ ``` lua
1909
+ -- <project-name>-scm-1.rockspec
1910
+ dependencies = {
1911
+ ...
1912
+ ' crud == <the-latest-tag>-1' ,
1913
+ ...
1914
+ }
1915
+ ```
1916
+
1917
+ 2. Add crud roles to your application configuration .
1918
+ Application must be a sharded one .
1919
+ It is required that ` roles.crud-storage` is enabled on each
1920
+ sharding storage .
1921
+
1922
+ ` ` ` yaml
1923
+ groups :
1924
+ routers :
1925
+ sharding :
1926
+ roles :
1927
+ - router
1928
+ roles :
1929
+ - roles .crud - router
1930
+ replicasets :
1931
+ router :
1932
+
1933
+ storages :
1934
+ sharding :
1935
+ roles :
1936
+ - storage
1937
+ roles :
1938
+ - roles .crud - storage
1939
+ replicasets :
1940
+ s - 1 :
1941
+ s - 2 :
1942
+ ```
1943
+
1944
+ <details>
1945
+ <summary> Full configuration example </ summary >
1946
+
1947
+ ` ` ` yaml
1948
+ credentials :
1949
+ users :
1950
+ replicator :
1951
+ password : replicating
1952
+ roles :
1953
+ - replication
1954
+ storage :
1955
+ password : storing - buckets
1956
+ roles :
1957
+ - sharding
1958
+ guest :
1959
+ roles :
1960
+ - super
1961
+
1962
+ sharding :
1963
+ bucket_count : 30000
1964
+
1965
+ replication :
1966
+ failover : manual
1967
+
1968
+ iproto :
1969
+ advertise :
1970
+ peer :
1971
+ login : replicator
1972
+ sharding :
1973
+ login : storage
1974
+
1975
+ groups :
1976
+ routers :
1977
+ sharding :
1978
+ roles :
1979
+ - router
1980
+ roles :
1981
+ - roles .crud - router
1982
+ replicasets :
1983
+ router :
1984
+ leader : router
1985
+ instances :
1986
+ router :
1987
+ iproto :
1988
+ listen :
1989
+ - uri : localhost :3301
1990
+ storages :
1991
+ sharding :
1992
+ roles :
1993
+ - storage
1994
+ roles :
1995
+ - roles .crud - storage
1996
+ app :
1997
+ module : mystorage
1998
+ replicasets :
1999
+ s - 1 :
2000
+ leader : s1 - master
2001
+ instances :
2002
+ s1 - master :
2003
+ iproto :
2004
+ listen :
2005
+ - uri : localhost :3302
2006
+ s1 - replica :
2007
+ iproto :
2008
+ listen :
2009
+ - uri : localhost :3303
2010
+ s - 2 :
2011
+ leader : s2 - master
2012
+ instances :
2013
+ s2 - replica :
2014
+ iproto :
2015
+ listen :
2016
+ - uri : localhost :3304
2017
+ s2 - master :
2018
+ iproto :
2019
+ listen :
2020
+ - uri : localhost :3305
2021
+ ```
2022
+ </ details >
2023
+
2024
+ 3. Set up your schema on storages (for example , through ` app.module` section in Tarantool 3 configuration .)
2025
+
2026
+ ` ` ` lua
2027
+ -- mystorage.lua
2028
+
2029
+ -- Schema setup is idempotent.
2030
+
2031
+
2032
+ box .watch (' box.status' , function ()
2033
+ if box .info .ro then
2034
+ return
2035
+ end
2036
+
2037
+ local customers_space = box .schema .space .create (' customers' , {
2038
+ format = {
2039
+ {name = ' id' , type = ' unsigned' },
2040
+ {name = ' bucket_id' , type = ' unsigned' },
2041
+ {name = ' name' , type = ' string' },
2042
+ {name = ' age' , type = ' number' },
2043
+ },
2044
+ if_not_exists = true ,
2045
+ })
2046
+
2047
+ customers_space :create_index (' id' , {
2048
+ parts = { {field = ' id' , is_nullable = false } },
2049
+ if_not_exists = true ,
2050
+ })
2051
+
2052
+ customers_space :create_index (' bucket_id' , {
2053
+ parts = { {field = ' bucket_id' , is_nullable = false } },
2054
+ if_not_exists = true ,
2055
+ })
2056
+
2057
+ customers_space :create_index (' age' , {
2058
+ parts = { {field = ' age' } },
2059
+ unique = false ,
2060
+ if_not_exists = true ,
2061
+ })
2062
+ end )
2063
+ ```
2064
+
2065
+ 4. Start the application cluster . You can check whether asynchronous bootstrap
2066
+ had finished through ` crud.storage_info()` calls on router .
2067
+
2068
+ Now your cluster contains storages that are configured to be used for
2069
+ CRUD - operations .
2070
+ You can simply call CRUD functions on the router to insert , select , and update
2071
+ data across the cluster .
2072
+
1836
2073
## Cartridge roles
1837
2074
1838
2075
` cartridge.roles.crud-storage` is a Tarantool Cartridge role that depends on the
0 commit comments