Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdn-origin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
easrng
cdn-origin
Commits
14100c29
Commit
14100c29
authored
7 years ago
by
Dean
Browse files
Options
Downloads
Patches
Plain Diff
fix race condition in weed/volume-cache.go, bump patch
parent
57e3eec0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cdn-origin.go
+1
-1
1 addition, 1 deletion
cdn-origin.go
weed/volume-cache.go
+13
-0
13 additions, 0 deletions
weed/volume-cache.go
with
14 additions
and
1 deletion
cdn-origin.go
+
1
−
1
View file @
14100c29
...
...
@@ -132,7 +132,7 @@ func main() {
log
.
Info
(
"Attempting to listen on "
+
listenAddr
)
server
:=
&
fasthttp
.
Server
{
Handler
:
h
,
Name
:
"whats-this/cdn-origin/0.1.
0
"
,
Name
:
"whats-this/cdn-origin/0.1.
1
"
,
ReadBufferSize
:
1024
*
6
,
// 6 KB
ReadTimeout
:
time
.
Minute
*
30
,
WriteTimeout
:
time
.
Minute
*
30
,
...
...
This diff is collapsed.
Click to expand it.
weed/volume-cache.go
+
13
−
0
View file @
14100c29
package
weed
import
"sync"
// VolumeCache stores a volume ID => volume URL map used for caching volume lookup responses from the master of a
// SeaweedFS cluster.
type
VolumeCache
struct
{
sync
.
RWMutex
volumeCache
map
[
uint32
][]
string
next
map
[
uint32
]
int
}
// Add adds a volume ID => location URL slice mapping to the volume cache.
func
(
v
*
VolumeCache
)
Add
(
id
uint32
,
urls
[]
string
)
{
v
.
Lock
()
defer
v
.
Unlock
()
v
.
volumeCache
[
id
]
=
urls
v
.
next
[
id
]
=
0
}
// Get returns all volume server URLs for a given volume ID.
func
(
v
*
VolumeCache
)
Get
(
id
uint32
)
[]
string
{
v
.
RLock
()
defer
v
.
RUnlock
()
vol
,
_
:=
v
.
volumeCache
[
id
]
return
vol
}
// GetNext returns the n+1th location URL for the given volume ID, n is tracked internally.
func
(
v
*
VolumeCache
)
GetNext
(
id
uint32
)
string
{
v
.
RLock
()
defer
v
.
RUnlock
()
vol
,
ok
:=
v
.
volumeCache
[
id
]
volLen
:=
len
(
vol
)
if
!
ok
||
volLen
==
0
{
...
...
@@ -36,11 +45,15 @@ func (v *VolumeCache) GetNext(id uint32) string {
// Remove removes a volume from the volume cache.
func
(
v
*
VolumeCache
)
Remove
(
id
uint32
)
{
v
.
Lock
()
defer
v
.
Unlock
()
delete
(
v
.
volumeCache
,
id
)
}
// Empty clears all data and returns the VolumeCache to it's initial state.
func
(
v
*
VolumeCache
)
Empty
()
{
v
.
Lock
()
defer
v
.
Unlock
()
v
.
volumeCache
=
map
[
uint32
][]
string
{}
v
.
next
=
map
[
uint32
]
int
{}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment