-
-
Notifications
You must be signed in to change notification settings - Fork 114
Add shared state multiwriter #872
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
Merged
spiccinini
merged 13 commits into
libremesh:master
from
spiccinini:add-shared-state-multiwriter
Jun 24, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3bc8c5b
lime-utils: add tables deepcompare utility
germanferrero abeeff6
sharedstate: add persistent shared state
germanferrero b0d3c9c
shared-state: fix indentation
germanferrero 2acaef2
tests shated-state: add newline at end of file
germanferrero 00979bb
shared-state: Configure cgi-bin url for persistent shared-state
germanferrero bf3f112
lime.utils: fix formatting
spiccinini ab1dc54
shared-state: some fixes
spiccinini 59f8551
shared-state: rename persistent files to multiwriter
spiccinini b6ab59c
shared-state: rename Persistent to MultiWriter
spiccinini 1e50aa4
shared-state: fix sync not updating keys
spiccinini dcb099e
shared-state: multiwriter use counter based merge strategy
spiccinini 029e15e
utils: early comparison of same table
germanferrero 60b2048
Merge pull request #5 from germanferrero/shared-state-multiwriter-dee…
spiccinini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/shared-state/files/usr/bin/shared-state-multiwriter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| #!/usr/bin/lua | ||
| --! Minimalistic CRDT-like shared state structure suitable for mesh networks | ||
| --! which handles conflicts in the same entry using last modified timestamp. | ||
| --! | ||
| --! Copyright (C) 2019 Gioacchino Mazzurco <gio@altermundi.net> | ||
| --! | ||
| --! This program is free software: you can redistribute it and/or modify | ||
| --! it under the terms of the GNU Affero General Public License version 3 as | ||
| --! published by the Free Software Foundation. | ||
| --! | ||
| --! This program is distributed in the hope that it will be useful, | ||
| --! but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| --! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| --! GNU Affero General Public License for more details. | ||
| --! | ||
| --! You should have received a copy of the GNU Affero General Public License | ||
| --! along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| if type(arg[2]) ~= "string" or arg[2]:len() < 1 then | ||
| print (arg[0], "needs CRDT name to be specified as second argument") | ||
| os.exit(-22) | ||
| end | ||
|
|
||
| local JSON = require("luci.jsonc") | ||
| local shared_state = require("shared-state") | ||
| require("nixio.util") | ||
|
|
||
| nixio.openlog("shared-state") | ||
| local logmask = "info" | ||
| if os.getenv("DEBUG") then | ||
| logmask = "debug" | ||
| end | ||
| nixio.setlogmask(logmask) | ||
|
|
||
| local sharedState = shared_state.SharedStateMultiWriter:new(arg[2], nixio.syslog) | ||
|
|
||
| if arg[1] == "insert" then | ||
| local inputTable = JSON.parse(io.stdin:read("*all")) or {} | ||
| sharedState:insert(inputTable) | ||
| elseif arg[1] == "get" then | ||
| local resultTable = sharedState:get() | ||
| print(JSON.stringify(resultTable)) | ||
| elseif arg[1] == "sync" then | ||
| local urls = {} | ||
| if arg[3] ~= nil then for i=3,#arg do table.insert(urls, arg[i]) end end | ||
| sharedState:sync(urls) | ||
| elseif arg[1] == "reqsync" then | ||
| local inputJson = JSON.parse(io.stdin:read("*all")) | ||
| sharedState:merge(inputJson) | ||
| print(sharedState:toJsonString()) | ||
| else | ||
| print(arg[0], "needs an operation name to be specified as first argument") | ||
| nixio.closelog() | ||
| os.exit(-22) | ||
| end | ||
|
|
||
| nixio.closelog() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.