From 098386773742ad37434be0d010cf52fc25bba51d Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sun, 25 Sep 2016 23:30:18 +0900 Subject: [PATCH 1/3] torusctl: support specifying ring type by init command --- cmd/torusctl/init.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/cmd/torusctl/init.go b/cmd/torusctl/init.go index a06069d..81e6dd8 100644 --- a/cmd/torusctl/init.go +++ b/cmd/torusctl/init.go @@ -16,11 +16,12 @@ import ( ) var ( - blockSize uint64 - blockSizeStr string - blockSpec string - noMakeRing bool - metaView bool + blockSize uint64 + blockSizeStr string + blockSpec string + inodeReplication int + metaView bool + initRingType string ) var initCommand = &cobra.Command{ @@ -33,8 +34,9 @@ var initCommand = &cobra.Command{ func init() { initCommand.Flags().StringVarP(&blockSizeStr, "block-size", "", "512KiB", "size of all data blocks in this storage cluster") initCommand.Flags().StringVarP(&blockSpec, "block-spec", "", "crc", "default replication/error correction applied to blocks in this storage cluster") - initCommand.Flags().BoolVar(&noMakeRing, "no-ring", false, "do not create the default ring as part of init") + initCommand.Flags().IntVarP(&inodeReplication, "inode-replication", "", 3, "default number of times to replicate inodes across the cluster") initCommand.Flags().BoolVar(&metaView, "view", false, "view metadata configured in this storage cluster") + initCommand.Flags().StringVar(&initRingType, "type", "ketama", "type of ring to create (empty, single, mod or ketama)") } func initPreRun(cmd *cobra.Command, args []string) { @@ -63,10 +65,21 @@ func initAction(cmd *cobra.Command, args []string) { } cfg := flagconfig.BuildConfigFromFlags() - ringType := ring.Ketama - if noMakeRing { + + var ringType torus.RingType + switch initRingType { + case "empty": ringType = ring.Empty + case "single": + ringType = ring.Single + case "mod": + ringType = ring.Mod + case "ketama": + ringType = ring.Ketama + default: + die(`invalid ring type %s (try "empty", "mod", "single" or "ketama")`, initRingType) } + err = torus.InitMDS("etcd", cfg, md, ringType) if err != nil { die("error writing metadata: %v", err) From e7795131a2cb55a85a59311adbfe41a688e94f3e Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sat, 5 Nov 2016 00:39:15 +0900 Subject: [PATCH 2/3] torusctl: support number of replication factor by init --- cmd/torusctl/init.go | 10 +++++++++- cmd/torusd/main.go | 3 ++- metadata.go | 6 +++--- metadata/etcd/global_funcs.go | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/torusctl/init.go b/cmd/torusctl/init.go index 81e6dd8..a7136d4 100644 --- a/cmd/torusctl/init.go +++ b/cmd/torusctl/init.go @@ -22,6 +22,7 @@ var ( inodeReplication int metaView bool initRingType string + initRepFactor int ) var initCommand = &cobra.Command{ @@ -37,6 +38,7 @@ func init() { initCommand.Flags().IntVarP(&inodeReplication, "inode-replication", "", 3, "default number of times to replicate inodes across the cluster") initCommand.Flags().BoolVar(&metaView, "view", false, "view metadata configured in this storage cluster") initCommand.Flags().StringVar(&initRingType, "type", "ketama", "type of ring to create (empty, single, mod or ketama)") + initCommand.Flags().IntVarP(&initRepFactor, "replication", "r", 2, "number of replicas") } func initPreRun(cmd *cobra.Command, args []string) { @@ -69,8 +71,14 @@ func initAction(cmd *cobra.Command, args []string) { var ringType torus.RingType switch initRingType { case "empty": + if initRepFactor != 0 { + die(`invalid number of replicas for empty ring. Use "--replication=0"`) + } ringType = ring.Empty case "single": + if initRepFactor != 1 { + die(`invalid number of replicas for single ring. Use "--replication=1"`) + } ringType = ring.Single case "mod": ringType = ring.Mod @@ -80,7 +88,7 @@ func initAction(cmd *cobra.Command, args []string) { die(`invalid ring type %s (try "empty", "mod", "single" or "ketama")`, initRingType) } - err = torus.InitMDS("etcd", cfg, md, ringType) + err = torus.InitMDS("etcd", cfg, md, ringType, initRepFactor) if err != nil { die("error writing metadata: %v", err) } diff --git a/cmd/torusd/main.go b/cmd/torusd/main.go index 75b2681..1d3153f 100644 --- a/cmd/torusd/main.go +++ b/cmd/torusd/main.go @@ -157,7 +157,8 @@ func runServer(cmd *cobra.Command, args []string) { err = torus.InitMDS("etcd", cfg, torus.GlobalMetadata{ BlockSize: 512 * 1024, DefaultBlockSpec: blockset.MustParseBlockLayerSpec("crc,base"), - }, ring.Ketama) + INodeReplication: 2, + }, ring.Ketama, 2) if err != nil { if err == torus.ErrExists { fmt.Println("debug-init: Already exists") diff --git a/metadata.go b/metadata.go index bb7b031..5d8c551 100644 --- a/metadata.go +++ b/metadata.go @@ -99,7 +99,7 @@ func CreateMetadataService(name string, cfg Config) (MetadataService, error) { } // InitMDSFunc is the signature of a function which preformats a metadata service. -type InitMDSFunc func(cfg Config, gmd GlobalMetadata, ringType RingType) error +type InitMDSFunc func(cfg Config, gmd GlobalMetadata, ringType RingType, repFactor int) error var initMDSFuncs map[string]InitMDSFunc @@ -118,9 +118,9 @@ func RegisterMetadataInit(name string, newFunc InitMDSFunc) { } // InitMDS calls the specific init function provided by a metadata package. -func InitMDS(name string, cfg Config, gmd GlobalMetadata, ringType RingType) error { +func InitMDS(name string, cfg Config, gmd GlobalMetadata, ringType RingType, repFactor int) error { clog.Debugf("running InitMDS for service type: %s", name) - return initMDSFuncs[name](cfg, gmd, ringType) + return initMDSFuncs[name](cfg, gmd, ringType, repFactor) } type WipeMDSFunc func(cfg Config) error diff --git a/metadata/etcd/global_funcs.go b/metadata/etcd/global_funcs.go index 86cd52c..ea9f6c9 100644 --- a/metadata/etcd/global_funcs.go +++ b/metadata/etcd/global_funcs.go @@ -11,7 +11,7 @@ import ( "golang.org/x/net/context" ) -func initEtcdMetadata(cfg torus.Config, gmd torus.GlobalMetadata, ringType torus.RingType) error { +func initEtcdMetadata(cfg torus.Config, gmd torus.GlobalMetadata, ringType torus.RingType, repFactor int) error { gmdbytes, err := json.Marshal(gmd) if err != nil { return err @@ -19,7 +19,7 @@ func initEtcdMetadata(cfg torus.Config, gmd torus.GlobalMetadata, ringType torus emptyRing, err := ring.CreateRing(&models.Ring{ Type: uint32(ringType), Version: 1, - ReplicationFactor: 2, + ReplicationFactor: uint32(repFactor), }) if err != nil { return err From 44958f54e8094efeeafd72dd2612ac49e5725676 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Sat, 5 Nov 2016 00:51:44 +0900 Subject: [PATCH 3/3] torusctl: update after rebased --- cmd/torusctl/init.go | 30 +++++++++++++++--------------- cmd/torusd/main.go | 1 - 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cmd/torusctl/init.go b/cmd/torusctl/init.go index a7136d4..44a63e8 100644 --- a/cmd/torusctl/init.go +++ b/cmd/torusctl/init.go @@ -16,13 +16,12 @@ import ( ) var ( - blockSize uint64 - blockSizeStr string - blockSpec string - inodeReplication int - metaView bool - initRingType string - initRepFactor int + blockSize uint64 + blockSizeStr string + blockSpec string + metaView bool + initRingType string + initRepFactor int ) var initCommand = &cobra.Command{ @@ -35,7 +34,6 @@ var initCommand = &cobra.Command{ func init() { initCommand.Flags().StringVarP(&blockSizeStr, "block-size", "", "512KiB", "size of all data blocks in this storage cluster") initCommand.Flags().StringVarP(&blockSpec, "block-spec", "", "crc", "default replication/error correction applied to blocks in this storage cluster") - initCommand.Flags().IntVarP(&inodeReplication, "inode-replication", "", 3, "default number of times to replicate inodes across the cluster") initCommand.Flags().BoolVar(&metaView, "view", false, "view metadata configured in this storage cluster") initCommand.Flags().StringVar(&initRingType, "type", "ketama", "type of ring to create (empty, single, mod or ketama)") initCommand.Flags().IntVarP(&initRepFactor, "replication", "r", 2, "number of replicas") @@ -66,8 +64,6 @@ func initAction(cmd *cobra.Command, args []string) { die("error parsing block-spec: %v", err) } - cfg := flagconfig.BuildConfigFromFlags() - var ringType torus.RingType switch initRingType { case "empty": @@ -76,10 +72,13 @@ func initAction(cmd *cobra.Command, args []string) { } ringType = ring.Empty case "single": - if initRepFactor != 1 { - die(`invalid number of replicas for single ring. Use "--replication=1"`) - } - ringType = ring.Single + die(`Currently single ring type is not supported by init. Use torusctl ring manual-change after adding one node."`) + /* + if initRepFactor != 1 { + die(`invalid number of replicas for single ring. Use "--replication=1"`) + } + iRingType = ring.Single + */ case "mod": ringType = ring.Mod case "ketama": @@ -87,11 +86,12 @@ func initAction(cmd *cobra.Command, args []string) { default: die(`invalid ring type %s (try "empty", "mod", "single" or "ketama")`, initRingType) } - + cfg := flagconfig.BuildConfigFromFlags() err = torus.InitMDS("etcd", cfg, md, ringType, initRepFactor) if err != nil { die("error writing metadata: %v", err) } + } func viewMetadata() { diff --git a/cmd/torusd/main.go b/cmd/torusd/main.go index 1d3153f..f360279 100644 --- a/cmd/torusd/main.go +++ b/cmd/torusd/main.go @@ -157,7 +157,6 @@ func runServer(cmd *cobra.Command, args []string) { err = torus.InitMDS("etcd", cfg, torus.GlobalMetadata{ BlockSize: 512 * 1024, DefaultBlockSpec: blockset.MustParseBlockLayerSpec("crc,base"), - INodeReplication: 2, }, ring.Ketama, 2) if err != nil { if err == torus.ErrExists {