Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

flagconfig: change the defaultEtcdAddress value from "127.0.0.1:2379" to "http://127.0.0.1:2379" #445

Closed
wants to merge 7 commits into from
4 changes: 4 additions & 0 deletions block/blockfile.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"golang.org/x/net/context"
)

/**
**using the torus file as the block device
**it extend from File and contains the BlockVolume
*/
type BlockFile struct {
*torus.File
vol *BlockVolume
Expand Down
Empty file modified cliconfig/config.go
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions cmd/torusblk/main.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func configureServer(cmd *cobra.Command, args []string) {
case debug:
capnslog.SetGlobalLogLevel(capnslog.DEBUG)
default:
capnslog.SetGlobalLogLevel(capnslog.INFO)
capnslog.SetGlobalLogLevel(capnslog.TRACE)
}
if logpkg != "" {
capnslog.SetGlobalLogLevel(capnslog.NOTICE)
capnslog.SetGlobalLogLevel(capnslog.TRACE)
rl := capnslog.MustRepoLogger("github.com/coreos/torus")
llc, err := rl.ParseLogLevelConfig(logpkg)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/torusctl/init.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func initAction(cmd *cobra.Command, args []string) {
if err != nil {
die("error writing metadata: %v", err)
}

fmt.Println("this mds init sucessed")
}

func viewMetadata() {
Expand Down
98 changes: 0 additions & 98 deletions cmd/torusctl/list-peers.go

This file was deleted.

85 changes: 82 additions & 3 deletions cmd/torusctl/peer.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package main

import (
"fmt"
"os"
"time"

"github.com/coreos/torus"
"github.com/coreos/torus/models"
"github.com/dustin/go-humanize"
"github.com/spf13/cobra"
)

var (
newPeers torus.PeerInfoList
allPeers bool
force bool
newPeers torus.PeerInfoList
allPeers bool
force bool
outputAsCSV bool
outputAsSI bool
)

var peerCommand = &cobra.Command{
Expand Down Expand Up @@ -44,6 +49,8 @@ func init() {
peerCommand.AddCommand(peerAddCommand, peerRemoveCommand, peerListCommand)
peerAddCommand.Flags().BoolVar(&allPeers, "all-peers", false, "add all peers")
peerRemoveCommand.PersistentFlags().BoolVar(&force, "force", false, "force-remove a UUID")
peerListCommand.Flags().BoolVarP(&outputAsCSV, "csv", "", false, "output as csv instead")
peerListCommand.Flags().BoolVarP(&outputAsSI, "si", "", false, "output sizes in powers of 1000")
}

func peerAction(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -141,3 +148,75 @@ func peerRemoveAction(cmd *cobra.Command, args []string) {
die("couldn't set new ring: %v", err)
}
}

func listPeersAction(cmd *cobra.Command, args []string) {
var totalStorage uint64
var usedStorage uint64

mds := mustConnectToMDS()
gmd := mds.GlobalMetadata()
peers, err := mds.GetPeers()
if err != nil {
die("couldn't get peers: %v", err)
}
ring, err := mds.GetRing()
if err != nil {
die("couldn't get ring: %v", err)
}
members := ring.Members()
table := NewTableWriter(os.Stdout)
table.SetHeader([]string{"Address", "UUID", "Size", "Used", "Member", "Updated", "Reb/Rep Data"})
rebalancing := false
for _, x := range peers {
ringStatus := "Avail"
if x.Address == "" {
continue
}
if members.Has(x.UUID) {
ringStatus = "OK"
}
table.Append([]string{
x.Address,
x.UUID,
bytesOrIbytes(x.TotalBlocks*gmd.BlockSize, outputAsSI),
bytesOrIbytes(x.UsedBlocks*gmd.BlockSize, outputAsSI),
ringStatus,
humanize.Time(time.Unix(0, x.LastSeen)),
bytesOrIbytes(x.RebalanceInfo.LastRebalanceBlocks*gmd.BlockSize*uint64(time.Second)/uint64(x.LastSeen+1-x.RebalanceInfo.LastRebalanceFinish), outputAsSI) + "/sec",
})
if x.RebalanceInfo.Rebalancing {
rebalancing = true
}
totalStorage += x.TotalBlocks * gmd.BlockSize
usedStorage += x.UsedBlocks * gmd.BlockSize
}

for _, x := range members {
ringStatus := "DOWN"
ok := false
for _, p := range peers {
if p.UUID == x {
ok = true
break
}
}
if ok {
continue
}
table.Append([]string{
"",
x,
"???",
"???",
ringStatus,
"Missing",
"",
})
}
if outputAsCSV {
table.RenderCSV()
} else {
table.Render()
fmt.Printf("Balanced: %v Usage: %5.2f%%\n", !rebalancing, (float64(usedStorage) / float64(totalStorage) * 100.0))
}
}
5 changes: 4 additions & 1 deletion cmd/torusctl/torusctl.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ var versionCommand = &cobra.Command{
}

func init() {
fmt.Println("start to init MDS...")
rootCommand.PersistentFlags().BoolVarP(&debug, "debug", "", false, "enable debug logging")
rootCommand.AddCommand(initCommand)
rootCommand.AddCommand(blockCommand)
rootCommand.AddCommand(listPeersCommand)
// rootCommand.AddCommand(listPeersCommand)
rootCommand.AddCommand(ringCommand)
rootCommand.AddCommand(peerCommand)
rootCommand.AddCommand(volumeCommand)
Expand All @@ -47,6 +48,8 @@ func init() {
rootCommand.AddCommand(configCommand)
rootCommand.AddCommand(completionCommand)
flagconfig.AddConfigFlags(rootCommand.PersistentFlags())

fmt.Println("MDS init finished...")
}

func main() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/torusd/main.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ func configureServer(cmd *cobra.Command, args []string) {
case debug:
capnslog.SetGlobalLogLevel(capnslog.DEBUG)
default:
capnslog.SetGlobalLogLevel(capnslog.INFO)
capnslog.SetGlobalLogLevel(capnslog.TRACE)
}
if logpkg != "" {
capnslog.SetGlobalLogLevel(capnslog.NOTICE)
capnslog.SetGlobalLogLevel(capnslog.TRACE)
rl := capnslog.MustRepoLogger("github.com/coreos/torus")
llc, err := rl.ParseLogLevelConfig(logpkg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion distributor/client.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (d *distClient) onPeerTimeout(uuid string) {
clog.Errorf("peer timeout err on close: %s", err)
}
delete(d.openConns, uuid)

}

func (d *distClient) getConn(uuid string) protocols.RPC {
d.mut.Lock()
if conn, ok := d.openConns[uuid]; ok {
Expand Down
4 changes: 4 additions & 0 deletions distributor/lru.go
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//implementation the LRU cache
package distributor

import (
Expand Down Expand Up @@ -26,12 +27,15 @@ func newCache(size int) *cache {
return &lru
}

//put a key-value pair into cache, nothing to be done if the key exist
func (lru *cache) Put(key string, value interface{}) {
if lru == nil {
return
}
lru.mut.Lock()
defer lru.mut.Unlock()

//if the key exist, nothing to be done
if _, ok := lru.get(key); ok {
return
}
Expand Down
2 changes: 1 addition & 1 deletion distributor/rebalance.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (d *Distributor) rebalanceTicker(closer chan struct{}) {
time.Sleep(time.Duration(250+rand.Intn(250)) * time.Millisecond)
exit:
for {
clog.Tracef("starting rebalance/gc cycle")
// clog.Tracef("starting rebalance/gc cycle")
volset, _, err := d.srv.MDS.GetVolumes()
if err != nil {
clog.Error(err)
Expand Down
Empty file modified heartbeat.go
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion internal/flagconfig/flagconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

const (
defaultTorusConfig = "/.torus/config.json"
defaultEtcdAddress = "127.0.0.1:2379"
defaultEtcdAddress = "http://127.0.0.1:2379"
)

var (
Expand Down
5 changes: 5 additions & 0 deletions internal/nbd/nbd.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (nbd *NBD) SetBlockSize(blocksize int64) error {
return nil
}

/**
*** This method is to find the available nbd* device
*** according to the device name to find if the /dev folder has this "file"
*** if the file is exist, then to check the /sys/block/nbd#/pid
*/
func FindDevice() (string, error) {
// FIXME: Oh god... fixme.
// find free nbd device
Expand Down
4 changes: 4 additions & 0 deletions internal/tcmu/connect.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ type torusHandler struct {

func (h *torusHandler) HandleCommand(cmd *tcmu.SCSICmd) (tcmu.SCSIResponse, error) {
switch cmd.Command() {
//query the storage basic information: verdor name, product name, product version
case scsi.Inquiry:
return tcmu.EmulateInquiry(cmd, h.inq)
//the signal sent by PC to make sure the storage device is stil alive.
case scsi.TestUnitReady:
return tcmu.EmulateTestUnitReady(cmd)
case scsi.ServiceActionIn16:
Expand All @@ -71,8 +73,10 @@ func (h *torusHandler) HandleCommand(cmd *tcmu.SCSICmd) (tcmu.SCSIResponse, erro
return tcmu.EmulateModeSense(cmd, true)
case scsi.ModeSelect, scsi.ModeSelect10:
return tcmu.EmulateModeSelect(cmd, true)
//Read10: sent by PC, to query the data from offset and length.
case scsi.Read6, scsi.Read10, scsi.Read12, scsi.Read16:
return tcmu.EmulateRead(cmd, h.file)
//write10:write the data from PC into the specified address[offset, length]
case scsi.Write6, scsi.Write10, scsi.Write12, scsi.Write16:
return h.handleWrite(cmd)
case scsi.SynchronizeCache, scsi.SynchronizeCache16:
Expand Down
3 changes: 2 additions & 1 deletion local_server.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func MkdirsFor(dir string) error {
}

func NewServer(cfg Config, metadataServiceKind, blockStoreKind string) (*Server, error) {
err := MkdirsFor(cfg.DataDir)

err := MkdirsFor(cfg.DataDir) //create two folders under the data-dirs, one is "metadata",anther is "block"
if err != nil {
return nil, err
}
Expand Down
Loading