[ARVADOS] updated: 335f749ab589d21c87301beb27c0bad84282f6d1
Git user
git at public.curoverse.com
Mon May 30 15:52:20 EDT 2016
Summary of changes:
services/keep-balance/balance.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
discards f12f13217fdb01584b2b017eda053b6207b1bd85 (commit)
via 335f749ab589d21c87301beb27c0bad84282f6d1 (commit)
This update added new revisions after undoing existing revisions. That is
to say, the old revision is not a strict subset of the new revision. This
situation occurs when you --force push a change and generate a repository
containing something like this:
* -- * -- B -- O -- O -- O (f12f13217fdb01584b2b017eda053b6207b1bd85)
\
N -- N -- N (335f749ab589d21c87301beb27c0bad84282f6d1)
When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 335f749ab589d21c87301beb27c0bad84282f6d1
Author: Tom Clegg <tom at curoverse.com>
Date: Mon May 30 15:52:16 2016 -0400
9162: Update comments, add config test.
diff --git a/services/keep-balance/balance.go b/services/keep-balance/balance.go
index 5659878..2a2480c 100644
--- a/services/keep-balance/balance.go
+++ b/services/keep-balance/balance.go
@@ -14,6 +14,18 @@ import (
"git.curoverse.com/arvados.git/sdk/go/keepclient"
)
+// CheckConfig returns an error if anything is wrong with the given
+// config and runOptions.
+func CheckConfig(config Config, runOptions RunOptions) error {
+ if len(config.KeepServiceList.Items) > 0 && config.KeepServiceTypes != nil {
+ return fmt.Errorf("cannot specify both KeepServiceList and KeepServiceTypes in config")
+ }
+ if !runOptions.Once && config.RunPeriod == arvados.Duration(0) {
+ return fmt.Errorf("you must either use the -once flag, or specify RunPeriod in config")
+ }
+ return nil
+}
+
// Balancer compares the contents of keepstore servers with the
// collections stored in Arvados, and issues pull/trash requests
// needed to get (closer to) the optimal data layout.
@@ -51,9 +63,7 @@ func (bal *Balancer) Run(config Config, runOptions RunOptions) (err error) {
defer timeMe(bal.Logger, "Run")()
- if len(config.KeepServiceList.Items) > 0 && config.KeepServiceTypes != nil {
- err = fmt.Errorf("cannot specify both KeepServiceList and KeepServiceTypes in config")
- } else if len(config.KeepServiceList.Items) > 0 {
+ if len(config.KeepServiceList.Items) > 0 {
err = bal.SetKeepServices(config.KeepServiceList)
} else {
err = bal.DiscoverKeepServices(&config.Client, config.KeepServiceTypes)
@@ -95,7 +105,10 @@ func (bal *Balancer) Run(config Config, runOptions RunOptions) (err error) {
func (bal *Balancer) SetKeepServices(srvList arvados.KeepServiceList) error {
bal.KeepServices = make(map[string]*KeepService)
for _, srv := range srvList.Items {
- bal.KeepServices[srv.UUID] = &KeepService{KeepService: srv}
+ bal.KeepServices[srv.UUID] = &KeepService{
+ KeepService: srv,
+ ChangeSet: &ChangeSet{},
+ }
}
return nil
}
@@ -111,7 +124,10 @@ func (bal *Balancer) DiscoverKeepServices(c *arvados.Client, okTypes []string) e
}
return c.EachKeepService(func(srv arvados.KeepService) error {
if ok[srv.ServiceType] {
- bal.KeepServices[srv.UUID] = &KeepService{KeepService: srv}
+ bal.KeepServices[srv.UUID] = &KeepService{
+ KeepService: srv,
+ ChangeSet: &ChangeSet{},
+ }
} else {
bal.logf("skipping %v with service type %q", srv.UUID, srv.ServiceType)
}
@@ -158,7 +174,7 @@ func (bal *Balancer) CheckSanityEarly(c *arvados.Client) error {
// running at a time.)
func (bal *Balancer) ClearTrashLists(c *arvados.Client) error {
for _, srv := range bal.KeepServices {
- srv.ChangeSet = ChangeSet{}
+ srv.ChangeSet = &ChangeSet{}
}
return bal.CommitTrash(c)
}
@@ -510,7 +526,7 @@ func (bal *Balancer) PrintStatistics() {
bal.logf("%s total usage", s.current)
bal.logf("===")
for _, srv := range bal.KeepServices {
- bal.logf("%s: %v\n", srv, &srv.ChangeSet)
+ bal.logf("%s: %v\n", srv, srv.ChangeSet)
}
bal.logf("===")
bal.printHistogram(s, 60)
diff --git a/services/keep-balance/balance_test.go b/services/keep-balance/balance_test.go
index dad10b0..682a5fb 100644
--- a/services/keep-balance/balance_test.go
+++ b/services/keep-balance/balance_test.go
@@ -197,7 +197,7 @@ func (bal *balancerSuite) try(c *check.C, t tester) {
blk.Replicas[i].Mtime = t
}
for _, srv := range bal.srvs {
- srv.ChangeSet = ChangeSet{}
+ srv.ChangeSet = &ChangeSet{}
}
bal.balanceBlock(knownBlkid(t.known), blk)
diff --git a/services/keep-balance/block_state.go b/services/keep-balance/block_state.go
index 9d15fdd..d607386 100644
--- a/services/keep-balance/block_state.go
+++ b/services/keep-balance/block_state.go
@@ -46,7 +46,8 @@ func NewBlockStateMap() *BlockStateMap {
}
}
-// Get returns a BlockState entry, allocating a new one if needed.
+// return a BlockState entry, allocating a new one if needed. (Private
+// method: not goroutine-safe.)
func (bsm *BlockStateMap) get(blkid arvados.SizedDigest) *BlockState {
// TODO? Allocate BlockState structs a slice at a time,
// instead of one at a time.
diff --git a/services/keep-balance/keep_service.go b/services/keep-balance/keep_service.go
index 6b7c431..f65355d 100644
--- a/services/keep-balance/keep_service.go
+++ b/services/keep-balance/keep_service.go
@@ -13,7 +13,7 @@ import (
// KeepService represents a keepstore server that is being rebalanced.
type KeepService struct {
arvados.KeepService
- ChangeSet
+ *ChangeSet
}
// String implements fmt.Stringer.
diff --git a/services/keep-balance/main.go b/services/keep-balance/main.go
index 1d7152e..42a8d63 100644
--- a/services/keep-balance/main.go
+++ b/services/keep-balance/main.go
@@ -13,8 +13,10 @@ import (
"git.curoverse.com/arvados.git/sdk/go/arvados"
)
-// Config indicates which servers are to be balanced. Config is loaded
-// from a JSON config file.
+// Config specifies site configuration, like API credentials and the
+// choice of which servers are to be balanced.
+//
+// Config is loaded from a JSON config file (see usage()).
type Config struct {
// Arvados API endpoint and credentials.
Client arvados.Client
@@ -30,8 +32,9 @@ type Config struct {
// RunOptions controls runtime behavior. The flags/options that belong
// here are the ones that are useful for interactive use. For example,
-// "dry run" is a runtime option rather than a config item because it
-// doesn't affect the balancing decisions being made.
+// "CommitTrash" is a runtime option rather than a config item because
+// it invokes a troubleshooting feature rather than expressing how
+// balancing is meant to be done at a given site.
//
// RunOptions fields are controlled by command line flags.
type RunOptions struct {
@@ -53,7 +56,7 @@ func main() {
serviceListPath := flag.String("config.KeepServiceList", "",
"`path` of json file with list of keep services to balance, as given by \"arv keep_service list\" "+
"(default: config[\"KeepServiceList\"], or if none given, get all available services and filter by config[\"KeepServiceTypes\"])")
- once := flag.Bool("once", false,
+ flag.BoolVar(&runOptions.Once, "once", false,
"balance once and then exit")
flag.BoolVar(&runOptions.CommitPulls, "commit-pulls", false,
"send pull requests (make more replicas of blocks that are underreplicated or are not in optimal rendezvous probe order)")
@@ -71,9 +74,6 @@ func main() {
if *serviceListPath != "" {
mustReadJSON(&config.KeepServiceList, *serviceListPath)
}
- if !*once && config.RunPeriod == arvados.Duration(0) {
- log.Fatal("You must either use the -once flag or specify a RunPeriod in your config file")
- }
if *debugFlag {
debugf = log.Printf
@@ -86,8 +86,10 @@ func main() {
if *dumpFlag {
runOptions.Dumper = log.New(os.Stdout, "", log.LstdFlags)
}
- var err error
- if *once {
+ err := CheckConfig(config, runOptions)
+ if err != nil {
+ // (don't run)
+ } else if runOptions.Once {
err = (&Balancer{}).Run(config, runOptions)
} else {
err = RunForever(config, runOptions, nil)
@@ -120,11 +122,11 @@ func RunForever(config Config, runOptions RunOptions, stop <-chan interface{}) e
sigUSR1 := make(chan os.Signal)
signal.Notify(sigUSR1, syscall.SIGUSR1)
- logger.Printf("starting in service mode, running every %v and on SIGUSR1", config.RunPeriod)
+ logger.Printf("starting up: will scan every %v and on SIGUSR1", config.RunPeriod)
for {
if !runOptions.CommitPulls && !runOptions.CommitTrash {
- logger.Print("WARNING: Running in service mode, but no changes will be committed.")
+ logger.Print("WARNING: Will scan periodically, but no changes will be committed.")
logger.Print("======= Consider using -commit-pulls and -commit-trash flags.")
}
@@ -140,13 +142,15 @@ func RunForever(config Config, runOptions RunOptions, stop <-chan interface{}) e
signal.Stop(sigUSR1)
return nil
case <-ticker.C:
+ logger.Print("timer went off")
case <-sigUSR1:
logger.Print("received SIGUSR1, resetting timer")
- // Reset the timer so we don't wake up too
- // soon after a run triggered by SIGUSR1.
+ // Reset the timer so we don't start the N+1st
+ // run too soon after the Nth run is triggered
+ // by SIGUSR1.
ticker.Stop()
ticker = time.NewTicker(time.Duration(config.RunPeriod))
}
- logger.Print("waking up")
+ logger.Print("starting next run")
}
}
diff --git a/services/keep-balance/main_test.go b/services/keep-balance/main_test.go
index 5e1619a..38a0b12 100644
--- a/services/keep-balance/main_test.go
+++ b/services/keep-balance/main_test.go
@@ -18,3 +18,26 @@ func (s *mainSuite) TestExampleJSON(c *check.C) {
c.Check(config.Client.AuthToken, check.Equals, "xyzzy")
c.Check(time.Duration(config.RunPeriod), check.Equals, 600 * time.Second)
}
+
+func (s *mainSuite) TestConfigJSONWithKeepServiceList(c *check.C) {
+ var config Config
+ c.Check(json.Unmarshal([]byte(`
+ {
+ "Client": {
+ "APIHost": "zzzzz.arvadosapi.com:443",
+ "AuthToken": "xyzzy",
+ "Insecure": false
+ },
+ "KeepServiceList": {
+ "items": [
+ {"uuid":"zzzzz-bi64l-abcdefghijklmno", "service_type":"disk", "service_host":"a.zzzzz.arvadosapi.com", "service_port":12345},
+ {"uuid":"zzzzz-bi64l-bcdefghijklmnop", "service_type":"blob", "service_host":"b.zzzzz.arvadosapi.com", "service_port":12345}
+ ]
+ },
+ "RunPeriod": "600s"
+ }`), &config), check.IsNil)
+ c.Assert(len(config.KeepServiceList.Items), check.Equals, 2)
+ c.Check(config.KeepServiceList.Items[0].UUID, check.Equals, "zzzzz-bi64l-abcdefghijklmno")
+ c.Check(config.KeepServiceList.Items[0].ServicePort, check.Equals, 12345)
+ c.Check(config.Client.AuthToken, check.Equals, "xyzzy")
+}
diff --git a/services/keep-balance/usage.go b/services/keep-balance/usage.go
index 8361479..eb9990c 100644
--- a/services/keep-balance/usage.go
+++ b/services/keep-balance/usage.go
@@ -21,9 +21,12 @@ var exampleConfigFile = []byte(`
func usage() {
fmt.Fprintf(os.Stderr, `
-keep-balance copies blocks to better positions so clients find them
-faster, and deletes excess copies of overreplicated and unreferenced
-blocks.
+
+keep-balance rebalances a set of keepstore servers. It creates new
+copies of underreplicated blocks, deletes excess copies of
+overreplicated and unreferenced blocks, and moves blocks to better
+positions (according to the rendezvous hash algorithm) so clients find
+them faster.
Usage: keep-balance -config path/to/config.json [options]
@@ -41,18 +44,21 @@ Example config file:
Client.Insecure should be true if your Arvados API endpoint uses
an unverifiable SSL/TLS certificate.
-Service mode:
+Periodic scanning:
- By default, keep-balance runs in service mode: do a balance
- operation, sleep, repeat.
+ By default, keep-balance operates periodically, i.e.: do a
+ scan/balance operation, sleep, repeat.
RunPeriod determines the interval between start times of
- successive balance operations. If a balance operation takes longer
- than RunPeriod, the next one will follow it immediately.
+ successive scan/balance operations. If a scan/balance operation
+ takes longer than RunPeriod, the next one will follow it
+ immediately.
If SIGUSR1 is received during an idle period between operations,
the next operation will start immediately.
+One-time scanning:
+
Use the -once flag to do a single operation and then exit. The
exit code will be zero if the operation was successful.
@@ -65,5 +71,13 @@ Committing:
Use the -commit-pull and -commit-trash flags to implement the
computed changes.
+Limitations:
+
+ keep-balance does not attempt to discover whether committed pull
+ and trash requests ever get carried out -- only that they are
+ accepted by the Keep services. If some services are full, new
+ copies of underreplicated blocks might never get made, only
+ repeatedly requested.
+
`, exampleConfigFile)
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list