-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Use an abstract lock layer to allow distributed lock between multiple Gitea instances #26486
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d15388c
Use an abstract lock layer to allow distributed lock between multiple…
lunny 45e783e
Fix bug
lunny a0a74d7
Merge branch 'main' into lunny/lock_abstract
lunny 7d568f7
Update modules/setting/sync.go
lunny 974f6bd
Update custom/conf/app.example.ini
lunny 8a62284
Update docs/content/administration/config-cheat-sheet.en-us.md
lunny 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -1395,6 +1395,11 @@ However, later updates removed those options, and now the only options are `gith | |
However, if you want to use actions from other git server, you can use a complete URL in `uses` field, it's supported by Gitea (but not GitHub). | ||
Like `uses: https://gitea.com/actions/checkout@v3` or `uses: http://your-git-server/actions/checkout@v3`. | ||
|
||
## Sync (`sync`) | ||
|
||
- `LOCK_SERVICE_TYPE`: **memory**: Lock service type, could be `memory` or `redis` | ||
- `LOCK_SERVICE_CONN_STR`: **\<empty\>**: Ignored when `LOCK_SERVICE_TYPE` is `memory`. For `redis` use something like `redis://127.0.0.1:6379/0` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example is different from test, which is |
||
|
||
## Other (`other`) | ||
|
||
- `SHOW_FOOTER_VERSION`: **true**: Show Gitea and Go version information in the footer. | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,37 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package setting | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/nosql" | ||
) | ||
|
||
// Sync represents configuration of sync | ||
var Sync = struct { | ||
LockServiceType string | ||
LockServiceConnStr string | ||
}{ | ||
LockServiceType: "memory", | ||
} | ||
|
||
func loadSyncFrom(rootCfg ConfigProvider) { | ||
sec := rootCfg.Section("sync") | ||
Sync.LockServiceType = sec.Key("LOCK_SERVICE_TYPE").MustString("memory") | ||
switch Sync.LockServiceType { | ||
case "memory": | ||
case "redis": | ||
connStr := sec.Key("LOCK_SERVICE_CONN_STR").String() | ||
if connStr == "" { | ||
log.Fatal("LOCK_SERVICE_CONN_STR is empty for redis") | ||
} | ||
u := nosql.ToRedisURI(connStr) | ||
if u == nil { | ||
log.Fatal("LOCK_SERVICE_CONN_STR %s is not a valid redis connection string", connStr) | ||
} | ||
Sync.LockServiceConnStr = connStr | ||
default: | ||
log.Fatal("Unknown sync lock service type: %s", Sync.LockServiceType) | ||
} | ||
} |
This file contains 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,35 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package setting | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadSyncConfig(t *testing.T) { | ||
t.Run("DefaultSyncConfig", func(t *testing.T) { | ||
iniStr := `` | ||
cfg, err := NewConfigProviderFromData(iniStr) | ||
assert.NoError(t, err) | ||
|
||
loadSyncFrom(cfg) | ||
assert.EqualValues(t, "memory", Sync.LockServiceType) | ||
}) | ||
|
||
t.Run("RedisSyncConfig", func(t *testing.T) { | ||
iniStr := ` | ||
[sync] | ||
LOCK_SERVICE_TYPE = redis | ||
LOCK_SERVICE_CONN_STR = addrs=127.0.0.1:6379 db=0 | ||
` | ||
cfg, err := NewConfigProviderFromData(iniStr) | ||
assert.NoError(t, err) | ||
|
||
loadSyncFrom(cfg) | ||
assert.EqualValues(t, "redis", Sync.LockServiceType) | ||
assert.EqualValues(t, "addrs=127.0.0.1:6379 db=0", Sync.LockServiceConnStr) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a small description of what this section does would be useful.
Sync
is such a universal term that it could mean anything, i.e. "PR reloading settings", "syncs with external mirrors", …Perhaps we even need to think about renaming this section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we just call it
lock
here, or maybecluster