Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3144ebc7
Commit
3144ebc7
authored
Apr 30, 2016
by
Hongchao Deng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
start etcd compactor in background
parent
93e3df8e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
compact.go
pkg/storage/etcd3/compact.go
+39
-1
etcd3.go
pkg/storage/storagebackend/etcd3.go
+2
-0
No files found.
pkg/storage/etcd3/compact.go
View file @
3144ebc7
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
etcd3
package
etcd3
import
(
import
(
"sync"
"time"
"time"
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3"
...
@@ -24,6 +25,43 @@ import (
...
@@ -24,6 +25,43 @@ import (
"golang.org/x/net/context"
"golang.org/x/net/context"
)
)
const
compactInterval
=
10
*
time
.
Minute
var
(
endpointsMapMu
sync
.
Mutex
endpointsMap
map
[
string
]
struct
{}
)
func
init
()
{
endpointsMap
=
make
(
map
[
string
]
struct
{})
}
// StartCompactor starts a compactor in the background in order to compact keys
// older than fixed time.
// We need to compact keys because we can't let on disk data grow forever.
// We save the most recent 10 minutes data. It should be enough for slow watchers and to tolerate burst.
// TODO: We might keep a longer history (12h) in the future once storage API can take
// advantage of multi-version key.
func
StartCompactor
(
ctx
context
.
Context
,
client
*
clientv3
.
Client
)
{
endpointsMapMu
.
Lock
()
defer
endpointsMapMu
.
Unlock
()
// We can't have multiple compaction jobs for the same cluster.
// Currently we rely on endpoints to differentiate clusters.
var
emptyStruct
struct
{}
for
_
,
ep
:=
range
client
.
Endpoints
()
{
if
_
,
ok
:=
endpointsMap
[
ep
];
ok
{
glog
.
V
(
4
)
.
Infof
(
"compactor already exists for endpoints %v"
)
return
}
}
for
_
,
ep
:=
range
client
.
Endpoints
()
{
endpointsMap
[
ep
]
=
emptyStruct
}
go
compactor
(
ctx
,
client
,
compactInterval
)
}
// compactor periodically compacts historical versions of keys in etcd.
// compactor periodically compacts historical versions of keys in etcd.
// After compaction, old versions of keys set before given interval will be gone.
// After compaction, old versions of keys set before given interval will be gone.
// Any API call for the old versions of keys will return error.
// Any API call for the old versions of keys will return error.
...
@@ -43,7 +81,6 @@ func compactor(ctx context.Context, client *clientv3.Client, interval time.Durat
...
@@ -43,7 +81,6 @@ func compactor(ctx context.Context, client *clientv3.Client, interval time.Durat
glog
.
Error
(
err
)
glog
.
Error
(
err
)
continue
continue
}
}
glog
.
Infof
(
"compactor: Compacted rev %d"
,
curRev
)
}
}
}
}
...
@@ -62,5 +99,6 @@ func compact(ctx context.Context, client *clientv3.Client, oldRev int64) (int64,
...
@@ -62,5 +99,6 @@ func compact(ctx context.Context, client *clientv3.Client, oldRev int64) (int64,
if
err
!=
nil
{
if
err
!=
nil
{
return
curRev
,
err
return
curRev
,
err
}
}
glog
.
Infof
(
"etcd: Compacted rev %d, endpoints %v"
,
oldRev
,
client
.
Endpoints
())
return
curRev
,
nil
return
curRev
,
nil
}
}
pkg/storage/storagebackend/etcd3.go
View file @
3144ebc7
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"strings"
"strings"
"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3"
"golang.org/x/net/context"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/storage/etcd3"
"k8s.io/kubernetes/pkg/storage/etcd3"
)
)
...
@@ -36,5 +37,6 @@ func newETCD3Storage(c Config) (storage.Interface, error) {
...
@@ -36,5 +37,6 @@ func newETCD3Storage(c Config) (storage.Interface, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
etcd3
.
StartCompactor
(
context
.
Background
(),
client
)
return
etcd3
.
New
(
client
,
c
.
Codec
,
c
.
Prefix
),
nil
return
etcd3
.
New
(
client
,
c
.
Codec
,
c
.
Prefix
),
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment