tigerbeetle-node 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,40 +20,6 @@ or
20
20
  npm install tigerbeetle-node
21
21
  ```
22
22
 
23
- **Development**
24
-
25
- Follow these steps to get up and running when cloning the repo:
26
- ```shell
27
- git clone --recurse-submodules https://github.com/coilhq/tigerbeetle-node.git
28
- cd tigerbeetle-node/
29
- yarn install --immutable
30
- ```
31
-
32
- Build locally using `yarn`:
33
- ```shell
34
- # Run the following from this directory:
35
- yarn && yarn build
36
- ```
37
-
38
- * **Please note: `yarn clean` will remove Zig and NodeAPI C headers, which mean you need to run:**
39
- ```shell
40
- ./scripts/postinstall.sh #Install Zig and NodeJS C Headers
41
- ```
42
-
43
- ***Yarn - Run Test***
44
- Ensure TigerBeetle (`init` & `start`) is running on the port configured in `test.ts`, then run:
45
- ```shell
46
- ./tigerbeetle init --cluster=1 --replica=0 --directory=.
47
- ./tigerbeetle start --cluster=1 --replica=0 --directory=. --addresses=3001
48
- yarn test
49
- ```
50
-
51
- ***Yarn - Run Benchmark***
52
- Run the benchmark (The `benchmark` will automatically start TigerBeetle on port `3001` _(single replica)_:
53
- ```shell
54
- yarn benchmark
55
- ```
56
-
57
23
  ## Usage
58
24
  A client needs to be configured with a `cluster_id` and `replica_addresses`.
59
25
  This instantiates the client where memory is allocated to internally buffer events to be sent.
@@ -121,7 +87,7 @@ The creation of an account can be linked to the successful creation of another b
121
87
  flags |= CreateAccountFlags.debits_must_not_exceed_credits
122
88
  ```
123
89
 
124
- ### Account lookup
90
+ ### Account Lookup
125
91
 
126
92
  The `id` of the account is used for lookups. Only matched accounts are returned.
127
93
  ```js
@@ -145,7 +111,7 @@ The `id` of the account is used for lookups. Only matched accounts are returned.
145
111
  */
146
112
  ```
147
113
 
148
- ### Creating a transfer
114
+ ### Creating a Transfer
149
115
 
150
116
  This creates a journal entry between two accounts.
151
117
  ```js
@@ -191,7 +157,7 @@ Transfers within a batch may also be linked (see [linked events](#linked-events)
191
157
  flags |= TransferFlags.pending
192
158
  ```
193
159
 
194
- ### Post a Pending transfer (2-phase)
160
+ ### Post a Pending Transfer (2-Phase)
195
161
 
196
162
  With `flags = post_pending_transfer`, TigerBeetle will accept the transfer. TigerBeetle will atomically rollback the changes to `debits_pending` and `credits_pending` of the appropriate accounts and apply them to the `debits_posted` and `credits_posted` balances.
197
163
  ```js
@@ -204,7 +170,7 @@ const post = {
204
170
  const errors = await client.createTransfers([post])
205
171
  ```
206
172
 
207
- ### Linked events
173
+ ### Linked Events
208
174
 
209
175
  When the `linked` flag is specified for the `createAccount`, `createTransfer`, `commitTransfer` event, it links an event with the next event in the batch, to create a chain of events, of arbitrary length, which all succeed or fail together. The tail of a chain is denoted by the first event without this flag. The last event in a batch may therefore never have the `linked` flag set as this would leave a chain open-ended. Multiple chains or individual events may coexist within a batch to succeed or fail independently. Events within a chain are executed within order, or are rolled back on error, so that the effect of each event in the chain is visible to the next, and so that the chain is either visible or invisible as a unit to subsequent events after the chain. The event that was the first to break the chain will have a unique error result. Other events in the chain will have their error result set to `linked_event_failed`.
210
176
 
@@ -248,3 +214,37 @@ const errors = await client.createTransfers(batch)
248
214
  * ]
249
215
  */
250
216
  ```
217
+
218
+ ### Development
219
+
220
+ Follow these steps to get up and running when cloning the repo:
221
+ ```shell
222
+ git clone --recurse-submodules https://github.com/coilhq/tigerbeetle-node.git
223
+ cd tigerbeetle-node/
224
+ yarn install --immutable
225
+ ```
226
+
227
+ Build locally using `yarn`:
228
+ ```shell
229
+ # Run the following from this directory:
230
+ yarn && yarn build
231
+ ```
232
+
233
+ * **Please note: `yarn clean` will remove Zig and NodeAPI C headers, which mean you need to run:**
234
+ ```shell
235
+ ./scripts/postinstall.sh #Install Zig and NodeJS C Headers
236
+ ```
237
+
238
+ ***Yarn - Run Test***
239
+ Ensure TigerBeetle (`init` & `start`) is running on the port configured in `test.ts`, then run:
240
+ ```shell
241
+ ./tigerbeetle init --cluster=1 --replica=0 --directory=.
242
+ ./tigerbeetle start --cluster=1 --replica=0 --directory=. --addresses=3001
243
+ yarn test
244
+ ```
245
+
246
+ ***Yarn - Run Benchmark***
247
+ Run the benchmark (The `benchmark` will automatically start TigerBeetle on port `3001` _(single replica)_:
248
+ ```shell
249
+ yarn benchmark
250
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tigerbeetle-node",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "TigerBeetle Node.js client",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -12,7 +12,9 @@ HEADERS_TARBALL=./build/`basename "$HEADERS_URL"`
12
12
  # Download, making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
13
13
  echo "Downloading $HEADERS_URL..."
14
14
  if command -v wget &> /dev/null; then
15
- wget --quiet --show-progress --output-document=$HEADERS_TARBALL $HEADERS_URL
15
+ # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
16
+ # Only A records (for ipv4) are used in DNS:
17
+ wget -4 --quiet --show-progress --output-document=$HEADERS_TARBALL $HEADERS_URL
16
18
  else
17
19
  curl --silent --progress-bar --output $HEADERS_TARBALL $HEADERS_URL
18
20
  fi
package/src/node.zig CHANGED
@@ -691,7 +691,7 @@ fn on_result(user_data: u128, operation: Operation, results: Client.Error![]cons
691
691
 
692
692
  if (results) |value| {
693
693
  const napi_results = switch (operation) {
694
- .reserved, .init, .register => {
694
+ .reserved, .root, .register => {
695
695
  translate.throw(env, "Reserved operation.") catch return;
696
696
  },
697
697
  .create_accounts => encode_napi_results_array(
@@ -1,46 +1,46 @@
1
- @echo off
2
- setlocal enabledelayedexpansion
3
-
4
- if "%~1" equ ":main" (
5
- shift /1
6
- goto main
7
- )
8
-
9
- cmd /d /c "%~f0" :main %*
10
- set ZIG_RESULT=%ERRORLEVEL%
11
- taskkill /F /IM tigerbeetle.exe >nul
12
-
13
- if !ZIG_RESULT! equ 0 (
14
- del /f benchmark.log
15
- ) else (
16
- echo.
17
- echo Error running benchmark, here are more details
18
- type benchmark.log
19
- )
20
-
21
- echo.
22
- exit /b
23
-
24
- :main
25
- zig\zig.exe build -Drelease-safe
26
- move zig-out\bin\tigerbeetle.exe . >nul
27
-
28
- for /l %%i in (0, 1, 0) do (
29
- echo Initializing replica %%i
30
- set ZIG_FILE=.\cluster_0000000000_replica_00%%i.tigerbeetle
31
- if exist "!ZIG_FILE!" DEL /F "!ZIG_FILE!"
32
- .\tigerbeetle.exe init --directory=. --cluster=0 --replica=%%i > benchmark.log 2>&1
33
- )
34
-
35
- for /l %%i in (0, 1, 0) do (
36
- echo Starting replica %%i
37
- start /B "tigerbeetle_%%i" .\tigerbeetle.exe start --directory=. --cluster=0 --addresses=3001 --replica=%%i > benchmark.log 2>&1
38
- )
39
-
40
- rem Wait for replicas to start, listen and connect:
41
- timeout /t 2
42
-
43
- echo.
44
- echo Benchmarking...
45
- zig\zig.exe run -OReleaseSafe src\benchmark.zig
46
- exit /b %errorlevel%
1
+ @echo off
2
+ setlocal enabledelayedexpansion
3
+
4
+ if "%~1" equ ":main" (
5
+ shift /1
6
+ goto main
7
+ )
8
+
9
+ cmd /d /c "%~f0" :main %*
10
+ set ZIG_RESULT=%ERRORLEVEL%
11
+ taskkill /F /IM tigerbeetle.exe >nul
12
+
13
+ if !ZIG_RESULT! equ 0 (
14
+ del /f benchmark.log
15
+ ) else (
16
+ echo.
17
+ echo Error running benchmark, here are more details
18
+ type benchmark.log
19
+ )
20
+
21
+ echo.
22
+ exit /b
23
+
24
+ :main
25
+ zig\zig.exe build -Drelease-safe
26
+ move zig-out\bin\tigerbeetle.exe . >nul
27
+
28
+ for /l %%i in (0, 1, 0) do (
29
+ echo Initializing replica %%i
30
+ set ZIG_FILE=.\cluster_0000000000_replica_00%%i.tigerbeetle
31
+ if exist "!ZIG_FILE!" DEL /F "!ZIG_FILE!"
32
+ .\tigerbeetle.exe init --directory=. --cluster=0 --replica=%%i > benchmark.log 2>&1
33
+ )
34
+
35
+ for /l %%i in (0, 1, 0) do (
36
+ echo Starting replica %%i
37
+ start /B "tigerbeetle_%%i" .\tigerbeetle.exe start --directory=. --cluster=0 --addresses=3001 --replica=%%i > benchmark.log 2>&1
38
+ )
39
+
40
+ rem Wait for replicas to start, listen and connect:
41
+ timeout /t 2
42
+
43
+ echo.
44
+ echo Benchmarking...
45
+ zig\zig.exe run -OReleaseSafe src\benchmark.zig
46
+ exit /b %errorlevel%
@@ -1,109 +1,109 @@
1
- @echo off
2
-
3
- set ZIG_RELEASE_DEFAULT=0.9.1
4
-
5
- :: Determine the Zig build:
6
- if "%~1"=="" (
7
- set ZIG_RELEASE=%ZIG_RELEASE_DEFAULT%
8
- ) else if "%~1"=="latest" (
9
- set ZIG_RELEASE=builds
10
- ) else (
11
- set ZIG_RELEASE=%~1
12
- )
13
-
14
- :: Checks format of release version.
15
- echo.%ZIG_RELEASE% | findstr /b /r /c:"builds" /c:"^[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*">nul || (echo.Unexpected release format. && exit 1)
16
-
17
- set ZIG_OS=windows
18
- set ZIG_ARCH=x86_64
19
-
20
- set ZIG_TARGET=zig-%ZIG_OS%-%ZIG_ARCH%
21
-
22
- :: Determine the build, split the JSON line on whitespace and extract the 2nd field:
23
- for /f "tokens=2" %%a in ('curl --silent https://ziglang.org/download/index.json ^| findstr %ZIG_TARGET% ^| findstr %ZIG_RELEASE%' ) do (
24
- set ZIG_URL=%%a
25
- )
26
-
27
- :: Then remove quotes and commas:
28
- for /f %%b in ("%ZIG_URL:,=%") do (
29
- set ZIG_URL=%%~b
30
- )
31
-
32
- :: Checks the ZIG_URL variable follows the expected format.
33
- echo.%ZIG_URL% | findstr /b /r /c:"https://ziglang.org/builds/" /c:"https://ziglang.org/download/%ZIG_RELEASE%">nul || (echo.Unexpected release URL format. && exit 1)
34
-
35
- if "%ZIG_RELEASE%"=="builds" (
36
- echo Installing Zig latest build...
37
- ) else (
38
- echo Installing Zig %ZIG_RELEASE% release build...
39
- )
40
-
41
- :: Using variable modifiers to determine the directory and filename from the URL:
42
- :: %%~ni Expands %%i to a file name only and %%~xi Expands %%i to a file name extension only.
43
- for /f %%i in ("%ZIG_URL%") do (
44
- set ZIG_DIRECTORY=%%~ni
45
- set ZIG_TARBALL=%%~nxi
46
- )
47
-
48
- :: Checks the ZIG_DIRECTORY variable follows the expected format.
49
- echo.%ZIG_DIRECTORY% | findstr /b /r /c:"zig-win64-" /c:"zig-windows-x86_64-">nul || (echo.Unexpected zip directory name format. && exit 1)
50
-
51
- :: Making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
52
- if exist %ZIG_TARBALL% (
53
- del /q %ZIG_TARBALL%
54
- if exist %ZIG_TARBALL% (
55
- echo Failed to delete %ZIG_TARBALL%.
56
- exit 1
57
- )
58
- )
59
-
60
- echo Downloading %ZIG_URL%...
61
- curl --silent --progress-bar --output %ZIG_TARBALL% %ZIG_URL%
62
- if not exist %ZIG_TARBALL% (
63
- echo Failed to download Zig zip file.
64
- exit 1
65
- )
66
-
67
- :: Replace any existing Zig installation so that we can install or upgrade:
68
- echo Removing any existing 'zig' and %ZIG_DIRECTORY% folders before extracting.
69
- if exist zig\ (
70
- rd /s /q zig\
71
- :: Ensure the directory has been deleted.
72
- if exist zig\ (
73
- echo The ‘zig’ directory could not be deleted.
74
- exit 1
75
- )
76
- )
77
-
78
- if exist %ZIG_DIRECTORY%\ (
79
- rd /s /q %ZIG_DIRECTORY%
80
- :: Ensure the directory has been deleted.
81
- if exist %ZIG_DIRECTORY% (
82
- echo The %ZIG_DIRECTORY% directory could not be deleted.
83
- exit 1
84
- )
85
- )
86
-
87
- :: Extract and then remove the downloaded tarball:
88
- echo Extracting %ZIG_TARBALL%...
89
- powershell -Command "Expand-Archive %ZIG_TARBALL% -DestinationPath ."
90
- if not exist %ZIG_TARBALL% (
91
- echo Failed to extract zip file.
92
- exit 1
93
- )
94
-
95
- echo Installing %ZIG_DIRECTORY% to 'zig' in current working directory...
96
- ren %ZIG_DIRECTORY% zig
97
- if exist %ZIG_DIRECTORY% (
98
- echo Failed to rename %ZIG_DIRECTORY% to zig.
99
- exit 1
100
- )
101
-
102
- :: Removes the zip file
103
- del /q %ZIG_TARBALL%
104
- if exist %ZIG_TARBALL% (
105
- echo Failed to delete %ZIG_TARBALL% file.
106
- exit 1
107
- )
108
-
109
- echo "Congratulations, you have successfully installed Zig version %ZIG_RELEASE%. Enjoy!"
1
+ @echo off
2
+
3
+ set ZIG_RELEASE_DEFAULT=0.9.1
4
+
5
+ :: Determine the Zig build:
6
+ if "%~1"=="" (
7
+ set ZIG_RELEASE=%ZIG_RELEASE_DEFAULT%
8
+ ) else if "%~1"=="latest" (
9
+ set ZIG_RELEASE=builds
10
+ ) else (
11
+ set ZIG_RELEASE=%~1
12
+ )
13
+
14
+ :: Checks format of release version.
15
+ echo.%ZIG_RELEASE% | findstr /b /r /c:"builds" /c:"^[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*">nul || (echo.Unexpected release format. && exit 1)
16
+
17
+ set ZIG_OS=windows
18
+ set ZIG_ARCH=x86_64
19
+
20
+ set ZIG_TARGET=zig-%ZIG_OS%-%ZIG_ARCH%
21
+
22
+ :: Determine the build, split the JSON line on whitespace and extract the 2nd field:
23
+ for /f "tokens=2" %%a in ('curl --silent https://ziglang.org/download/index.json ^| findstr %ZIG_TARGET% ^| findstr %ZIG_RELEASE%' ) do (
24
+ set ZIG_URL=%%a
25
+ )
26
+
27
+ :: Then remove quotes and commas:
28
+ for /f %%b in ("%ZIG_URL:,=%") do (
29
+ set ZIG_URL=%%~b
30
+ )
31
+
32
+ :: Checks the ZIG_URL variable follows the expected format.
33
+ echo.%ZIG_URL% | findstr /b /r /c:"https://ziglang.org/builds/" /c:"https://ziglang.org/download/%ZIG_RELEASE%">nul || (echo.Unexpected release URL format. && exit 1)
34
+
35
+ if "%ZIG_RELEASE%"=="builds" (
36
+ echo Installing Zig latest build...
37
+ ) else (
38
+ echo Installing Zig %ZIG_RELEASE% release build...
39
+ )
40
+
41
+ :: Using variable modifiers to determine the directory and filename from the URL:
42
+ :: %%~ni Expands %%i to a file name only and %%~xi Expands %%i to a file name extension only.
43
+ for /f %%i in ("%ZIG_URL%") do (
44
+ set ZIG_DIRECTORY=%%~ni
45
+ set ZIG_TARBALL=%%~nxi
46
+ )
47
+
48
+ :: Checks the ZIG_DIRECTORY variable follows the expected format.
49
+ echo.%ZIG_DIRECTORY% | findstr /b /r /c:"zig-win64-" /c:"zig-windows-x86_64-">nul || (echo.Unexpected zip directory name format. && exit 1)
50
+
51
+ :: Making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
52
+ if exist %ZIG_TARBALL% (
53
+ del /q %ZIG_TARBALL%
54
+ if exist %ZIG_TARBALL% (
55
+ echo Failed to delete %ZIG_TARBALL%.
56
+ exit 1
57
+ )
58
+ )
59
+
60
+ echo Downloading %ZIG_URL%...
61
+ curl --silent --progress-bar --output %ZIG_TARBALL% %ZIG_URL%
62
+ if not exist %ZIG_TARBALL% (
63
+ echo Failed to download Zig zip file.
64
+ exit 1
65
+ )
66
+
67
+ :: Replace any existing Zig installation so that we can install or upgrade:
68
+ echo Removing any existing 'zig' and %ZIG_DIRECTORY% folders before extracting.
69
+ if exist zig\ (
70
+ rd /s /q zig\
71
+ :: Ensure the directory has been deleted.
72
+ if exist zig\ (
73
+ echo The ‘zig’ directory could not be deleted.
74
+ exit 1
75
+ )
76
+ )
77
+
78
+ if exist %ZIG_DIRECTORY%\ (
79
+ rd /s /q %ZIG_DIRECTORY%
80
+ :: Ensure the directory has been deleted.
81
+ if exist %ZIG_DIRECTORY% (
82
+ echo The %ZIG_DIRECTORY% directory could not be deleted.
83
+ exit 1
84
+ )
85
+ )
86
+
87
+ :: Extract and then remove the downloaded tarball:
88
+ echo Extracting %ZIG_TARBALL%...
89
+ powershell -Command "Expand-Archive %ZIG_TARBALL% -DestinationPath ."
90
+ if not exist %ZIG_TARBALL% (
91
+ echo Failed to extract zip file.
92
+ exit 1
93
+ )
94
+
95
+ echo Installing %ZIG_DIRECTORY% to 'zig' in current working directory...
96
+ ren %ZIG_DIRECTORY% zig
97
+ if exist %ZIG_DIRECTORY% (
98
+ echo Failed to rename %ZIG_DIRECTORY% to zig.
99
+ exit 1
100
+ )
101
+
102
+ :: Removes the zip file
103
+ del /q %ZIG_TARBALL%
104
+ if exist %ZIG_TARBALL% (
105
+ echo Failed to delete %ZIG_TARBALL% file.
106
+ exit 1
107
+ )
108
+
109
+ echo "Congratulations, you have successfully installed Zig version %ZIG_RELEASE%. Enjoy!"
@@ -40,7 +40,9 @@ ZIG_TARGET="zig-$ZIG_OS-$ZIG_ARCH"
40
40
 
41
41
  # Determine the build, split the JSON line on whitespace and extract the 2nd field, then remove quotes and commas:
42
42
  if command -v wget &> /dev/null; then
43
- ZIG_URL=`wget --quiet -O - https://ziglang.org/download/index.json | grep -F "$ZIG_TARGET" | grep -F "$ZIG_RELEASE" | awk '{print $2}' | sed 's/[",]//g'`
43
+ # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
44
+ # Only A records (for ipv4) are used in DNS:
45
+ ZIG_URL=`wget -4 --quiet -O - https://ziglang.org/download/index.json | grep -F "$ZIG_TARGET" | grep -F "$ZIG_RELEASE" | awk '{print $2}' | sed 's/[",]//g'`
44
46
  else
45
47
  ZIG_URL=`curl --silent https://ziglang.org/download/index.json | grep -F "$ZIG_TARGET" | grep -F "$ZIG_RELEASE" | awk '{print $2}' | sed 's/[",]//g'`
46
48
  fi
@@ -58,7 +60,9 @@ ZIG_DIRECTORY=`basename "$ZIG_TARBALL" .tar.xz`
58
60
  # Download, making sure we download to the same output document, without wget adding "-1" etc. if the file was previously partially downloaded:
59
61
  echo "Downloading $ZIG_URL..."
60
62
  if command -v wget &> /dev/null; then
61
- wget --quiet --show-progress --output-document=$ZIG_TARBALL $ZIG_URL
63
+ # -4 forces `wget` to connect to ipv4 addresses, as ipv6 fails to resolve on certain distros.
64
+ # Only A records (for ipv4) are used in DNS:
65
+ wget -4 --quiet --show-progress --output-document=$ZIG_TARBALL $ZIG_URL
62
66
  else
63
67
  curl --silent --progress-bar --output $ZIG_TARBALL $ZIG_URL
64
68
  fi
@@ -1,48 +1,48 @@
1
- :: Installs Zig if needed and runs the VOPR
2
- @echo off
3
-
4
- :: Install Zig if a zig folder does not already exist:
5
- if not exist zig\ (
6
- :: Installs the latest version of Zig
7
- call scripts\install_zig.bat
8
- :: Checks that the Zig folder now exists
9
- if not exist zig\ (
10
- echo The Zig installation failed.
11
- exit 1
12
- )
13
- echo Running the TigerBeetle VOPR for the first time...
14
- echo Visit https://www.tigerbeetle.com
15
- )
16
-
17
- :: If a seed is provided as an argument then replay the seed, otherwise test 1,000 seeds:
18
- if not "%~1"=="" (
19
- :: Build in fast ReleaseSafe mode if required, useful where you don't need debug logging:
20
- if "%~2"=="-OReleaseSafe" (
21
- echo Replaying seed %~1 in ReleaseSafe mode...
22
- call zig\zig run src\simulator.zig -OReleaseSafe -- %~1
23
- if not %ERRORLEVEL%==0 (
24
- echo Cannot replay the %~1 seed using the VOPR.
25
- exit 1
26
- )
27
- ) else (
28
- echo Replaying seed %~1 in Debug mode with full debug logging enabled...
29
- call zig\zig run src\simulator.zig -ODebug -- %~1
30
- if not %ERRORLEVEL%==0 (
31
- echo Cannot run the VOPR.
32
- exit 1
33
- )
34
- )
35
- ) else (
36
- call zig\zig build-exe src\simulator.zig -OReleaseSafe
37
- if not %ERRORLEVEL%==0 (
38
- echo Cannot run the VOPR.
39
- exit 1
40
- )
41
- for %%i in (1,1,1000) do (
42
- call simulator
43
- if not %ERRORLEVEL%==0 (
44
- echo Cannot run a seed using the VOPR.
45
- exit 1
46
- )
47
- )
1
+ :: Installs Zig if needed and runs the VOPR
2
+ @echo off
3
+
4
+ :: Install Zig if a zig folder does not already exist:
5
+ if not exist zig\ (
6
+ :: Installs the latest version of Zig
7
+ call scripts\install_zig.bat
8
+ :: Checks that the Zig folder now exists
9
+ if not exist zig\ (
10
+ echo The Zig installation failed.
11
+ exit 1
12
+ )
13
+ echo Running the TigerBeetle VOPR for the first time...
14
+ echo Visit https://www.tigerbeetle.com
15
+ )
16
+
17
+ :: If a seed is provided as an argument then replay the seed, otherwise test 1,000 seeds:
18
+ if not "%~1"=="" (
19
+ :: Build in fast ReleaseSafe mode if required, useful where you don't need debug logging:
20
+ if "%~2"=="-OReleaseSafe" (
21
+ echo Replaying seed %~1 in ReleaseSafe mode...
22
+ call zig\zig run src\simulator.zig -OReleaseSafe -- %~1
23
+ if not %ERRORLEVEL%==0 (
24
+ echo Cannot replay the %~1 seed using the VOPR.
25
+ exit 1
26
+ )
27
+ ) else (
28
+ echo Replaying seed %~1 in Debug mode with full debug logging enabled...
29
+ call zig\zig run src\simulator.zig -ODebug -- %~1
30
+ if not %ERRORLEVEL%==0 (
31
+ echo Cannot run the VOPR.
32
+ exit 1
33
+ )
34
+ )
35
+ ) else (
36
+ call zig\zig build-exe src\simulator.zig -OReleaseSafe
37
+ if not %ERRORLEVEL%==0 (
38
+ echo Cannot run the VOPR.
39
+ exit 1
40
+ )
41
+ for %%i in (1,1,1000) do (
42
+ call simulator
43
+ if not %ERRORLEVEL%==0 (
44
+ echo Cannot run a seed using the VOPR.
45
+ exit 1
46
+ )
47
+ )
48
48
  )
@@ -57,25 +57,23 @@ pub const transfers_max = switch (deployment_environment) {
57
57
  /// This impacts the amount of memory allocated at initialization by the server.
58
58
  pub const transfers_pending_max = transfers_max;
59
59
 
60
- /// The maximum size of the journal file:
61
- /// This is pre-allocated and zeroed for performance when initialized.
62
- /// Writes within this file never extend the filesystem inode size reducing the cost of fdatasync().
63
- /// This enables static allocation of disk space so that appends cannot fail with ENOSPC.
64
- /// This also enables us to detect filesystem inode corruption that would change the journal size.
65
- pub const journal_size_max = switch (deployment_environment) {
66
- .production => 128 * 1024 * 1024 * 1024,
67
- else => 128 * 1024 * 1024,
68
- };
69
-
70
60
  /// The maximum number of batch entries in the journal file:
71
61
  /// A batch entry may contain many transfers, so this is not a limit on the number of transfers.
72
62
  /// We need this limit to allocate space for copies of batch headers at the start of the journal.
73
63
  /// These header copies enable us to disentangle corruption from crashes and recover accordingly.
74
- pub const journal_headers_max = switch (deployment_environment) {
75
- .production => 1024 * 1024,
76
- else => 16384,
64
+ pub const journal_slot_count = switch (deployment_environment) {
65
+ .production => 1024,
66
+ else => 128,
77
67
  };
78
68
 
69
+ /// The maximum size of the journal file:
70
+ /// This is pre-allocated and zeroed for performance when initialized.
71
+ /// Writes within this file never extend the filesystem inode size reducing the cost of fdatasync().
72
+ /// This enables static allocation of disk space so that appends cannot fail with ENOSPC.
73
+ /// This also enables us to detect filesystem inode corruption that would change the journal size.
74
+ // TODO remove this; just allocate a part of the total storage for the journal
75
+ pub const journal_size_max = journal_slot_count * (128 + message_size_max);
76
+
79
77
  /// The maximum number of connections that can be held open by the server at any time:
80
78
  pub const connections_max = replicas_max + clients_max;
81
79
 
@@ -224,6 +222,10 @@ pub const clock_synchronization_window_min_ms = 2000;
224
222
  /// If a window expires because of this then it is likely that the clock epoch will also be expired.
225
223
  pub const clock_synchronization_window_max_ms = 20000;
226
224
 
225
+ // TODO Move these to a separate "internal computed constants" file.
226
+ pub const journal_size_headers = journal_slot_count * 128; // 128 == @sizeOf(Header)
227
+ pub const journal_size_prepares = journal_slot_count * message_size_max;
228
+
227
229
  comptime {
228
230
  // vsr.parse_address assumes that config.address/config.port are valid.
229
231
  _ = std.net.Address.parseIp4(address, 0) catch unreachable;
@@ -232,4 +234,6 @@ comptime {
232
234
  // Avoid latency issues from setting sndbuf too high:
233
235
  assert(tcp_sndbuf_replica <= 16 * 1024 * 1024);
234
236
  assert(tcp_sndbuf_client <= 16 * 1024 * 1024);
237
+
238
+ assert(journal_size_max == journal_size_headers + journal_size_prepares);
235
239
  }
@@ -31,7 +31,7 @@ pub fn request(
31
31
  ) !void {
32
32
  const allocator = std.heap.page_allocator;
33
33
  const client_id = std.crypto.random.int(u128);
34
- const cluster_id: u32 = 0;
34
+ const cluster_id: u32 = 1;
35
35
  var addresses = [_]std.net.Address{try std.net.Address.parseIp4("127.0.0.1", config.port)};
36
36
 
37
37
  var io = try IO.init(32, 0);
@@ -51,7 +51,7 @@ pub fn request(
51
51
 
52
52
  message_bus.set_on_message(*Client, &client, Client.on_message);
53
53
 
54
- var message = client.get_message();
54
+ const message = client.get_message();
55
55
  defer client.unref(message);
56
56
 
57
57
  const body = std.mem.asBytes(&batch);
@@ -6,15 +6,15 @@ const Transfer = tb.Transfer;
6
6
  pub fn main() !void {
7
7
  const transfers = [_]Transfer{
8
8
  Transfer{
9
- .id = 1000,
9
+ .id = 1,
10
10
  .debit_account_id = 1,
11
11
  .credit_account_id = 2,
12
12
  .user_data = 0,
13
13
  .reserved = 0,
14
14
  .pending_id = 0,
15
- .ledger = 0,
16
15
  .timeout = 0,
17
- .code = 0,
16
+ .ledger = 710, // Let's use the ISO-4217 Code Number for ZAR
17
+ .code = 1,
18
18
  .flags = .{},
19
19
  .amount = 1000,
20
20
  },