本文整理汇总了Golang中github.com/lpabon/godbc.Check函数的典型用法代码示例。如果您正苦于以下问题:Golang Check函数的具体用法?Golang Check怎么用?Golang Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: reader
func (c *Log) reader() {
defer c.wg.Done()
for s := range c.chreader {
s.lock.Lock()
// Reset the bufferIO managers
s.data.Reset()
// Move to the next offset
c.current += 1
c.current = c.current % c.numsegments
if 0 == c.current {
c.stats.Wrapped()
c.wrapped = true
}
s.offset = int64(c.current) * int64(c.segmentsize)
if c.wrapped {
start := time.Now()
n, err := c.fp.ReadAt(s.segmentbuf, s.offset)
end := time.Now()
c.stats.SegmentReadTimeRecord(end.Sub(start))
godbc.Check(n == len(s.segmentbuf))
godbc.Check(err == nil)
}
s.lock.Unlock()
c.chavailable <- s
}
}
示例2: Start
func (l *Log) Start() {
godbc.Require(l.size != 0)
godbc.Require(l.Msgchan != nil)
godbc.Require(l.chwriting != nil)
godbc.Require(l.chavailable != nil)
godbc.Require(l.chreader != nil)
godbc.Require(l.segmentbuffers == len(l.segments))
godbc.Require(l.segmentbuffers == len(l.chreader))
godbc.Require(0 == len(l.chavailable))
godbc.Require(0 == len(l.chwriting))
// Set up the first available segment
l.segment = <-l.chreader
l.segment.offset = int64(l.current) * int64(l.segmentsize)
if l.wrapped {
n, err := l.fp.ReadAt(l.segment.segmentbuf, l.segment.offset)
godbc.Check(n == len(l.segment.segmentbuf), n)
godbc.Check(err == nil)
}
// Now that we are sure everything is clean,
// we can start the goroutines
for i := 0; i < 32; i++ {
l.wg.Add(1)
go l.logread()
}
go l.server()
go l.writer()
go l.reader()
l.wg.Add(3)
}
示例3: put
func (c *Log) put(msg *message.Message) error {
iopkt := msg.IoPkt()
godbc.Require(iopkt.LogBlock < c.blocks)
// Make sure the block number curresponds to the
// current segment. If not, c.sync() will place
// the next available segment into c.segment
for !c.inRange(iopkt.LogBlock, c.segment) {
c.sync()
}
// get log offset
offset := c.offset(iopkt.LogBlock)
// Write to current buffer
n, err := c.segment.data.WriteAt(iopkt.Buffer, offset-c.segment.offset)
godbc.Check(n == len(iopkt.Buffer))
godbc.Check(err == nil)
c.segment.written = true
// We have written the data, and we are done with the message
msg.Done()
return err
}
示例4: GenUUID
// Return a 16-byte uuid
func GenUUID() string {
uuid := make([]byte, 16)
n, err := rand.Read(uuid)
godbc.Check(n == len(uuid), n, len(uuid))
godbc.Check(err == nil, err)
return hex.EncodeToString(uuid)
}
示例5: ioAt
func (a *Asu) ioAt(b []byte, offset int64, isread bool) (n int, err error) {
godbc.Require(a.fpsize != 0)
// Head
head_fp := int(offset / a.fpsize)
head_fp_off := int64(offset % a.fpsize)
godbc.Check(head_fp < len(a.fps), head_fp, len(a.fps))
// Tail
tail_fp := int((offset + int64(len(b))) / (a.fpsize + 4*KB))
godbc.Check(tail_fp < len(a.fps), tail_fp, len(a.fps), offset, len(b), a.fpsize)
if head_fp == tail_fp {
if isread {
return a.fps[head_fp].ReadAt(b, head_fp_off)
} else {
return a.fps[head_fp].WriteAt(b, head_fp_off)
}
} else {
var (
wg sync.WaitGroup
head_n, tail_n int
head_err, tail_err error
)
wg.Add(2)
// Read head
go func() {
defer wg.Done()
if isread {
head_n, head_err = a.fps[head_fp].ReadAt(b[:a.fpsize-head_fp_off], head_fp_off)
} else {
head_n, head_err = a.fps[head_fp].WriteAt(b[:a.fpsize-head_fp_off], head_fp_off)
}
}()
// Read tail
go func() {
defer wg.Done()
if isread {
tail_n, tail_err = a.fps[tail_fp].ReadAt(b[a.fpsize-head_fp_off:], 0)
} else {
tail_n, tail_err = a.fps[tail_fp].WriteAt(b[a.fpsize-head_fp_off:], 0)
}
}()
wg.Wait()
if head_err != nil {
return head_n, head_err
} else if tail_err != nil {
return tail_n, tail_err
} else {
return head_n + tail_n, nil
}
}
}
示例6: GenUUID
func GenUUID() string {
uuid := make([]byte, 16)
n, err := rand.Read(uuid)
godbc.Check(n == len(uuid), n, len(uuid))
godbc.Check(err == nil, err)
// TODO: verify the two lines implement RFC 4122 correctly
uuid[8] = 0x80 // variant bits see page 5
uuid[4] = 0x40 // version 4 Pseudo Random, see page 7
return hex.EncodeToString(uuid)
}
示例7: DestroyCheck
func (b *BrickEntry) DestroyCheck(db *bolt.DB, executor executors.Executor) error {
godbc.Require(db != nil)
godbc.Require(b.TpSize > 0)
godbc.Require(b.Info.Size > 0)
// Get node hostname
var host string
err := db.View(func(tx *bolt.Tx) error {
node, err := NewNodeEntryFromId(tx, b.Info.NodeId)
if err != nil {
return err
}
host = node.ManageHostName()
godbc.Check(host != "")
return nil
})
if err != nil {
return err
}
// Create request
req := &executors.BrickRequest{}
req.Name = b.Info.Id
req.Size = b.Info.Size
req.TpSize = b.TpSize
req.VgId = b.Info.DeviceId
// Check brick on node
return executor.BrickDestroyCheck(host, req)
}
示例8: Destroy
func (b *Brick) Destroy() error {
godbc.Require(b.NodeId != "")
godbc.Require(b.Path != "")
godbc.Require(b.db != nil)
// Just for now, it will work wih https://github.com/lpabon/vagrant-gfsm
sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
godbc.Check(sshexec != nil)
// Get node name
var nodename string
err := b.db.Reader(func() error {
nodename = b.db.nodes[b.NodeId].Info.Name
return nil
})
// Delete brick storage
commands := []string{
fmt.Sprintf("sudo umount /gluster/brick_%v", b.Id),
fmt.Sprintf("sudo lvremove -f vg_%v/tp_%v", b.DeviceId, b.Id),
fmt.Sprintf("sudo rmdir /gluster/brick_%v", b.Id),
}
_, err = sshexec.ConnectAndExec(nodename+":22", commands, nil)
if err != nil {
return err
}
err = b.FreeStorage()
return err
}
示例9: writer
func (c *Log) writer() {
defer c.wg.Done()
for s := range c.chwriting {
if s.written {
start := time.Now()
n, err := c.fp.WriteAt(s.segmentbuf, s.offset)
end := time.Now()
s.written = false
c.stats.WriteTimeRecord(end.Sub(start))
godbc.Check(n == len(s.segmentbuf))
godbc.Check(err == nil)
} else {
c.stats.SegmentSkipped()
}
c.chreader <- s
}
close(c.chreader)
}
示例10: CreateGlusterVolume
func (v *VolumeEntry) CreateGlusterVolume() error {
// Get node name
var nodename string
var cmd string
err := v.db.Reader(func() error {
nodename = v.db.nodes[v.State.Bricks[0].NodeId].Info.Name
cmd = fmt.Sprintf("sudo gluster volume create %v replica %v ",
v.Info.Name, v.State.Replica)
for brick := range v.State.Bricks {
cmd += fmt.Sprintf("%v:/gluster/brick_%v/brick ",
v.db.nodes[v.State.Bricks[brick].NodeId].Info.Name, v.State.Bricks[brick].Id)
}
return nil
})
if err != nil {
return err
}
// Create gluster volume command
// :TODO: Add force for now. It will allow silly bricks on the same systems
// to work. Please remove once we add the intelligent ring
cmd += " force"
// Just for now, it will work wih https://github.com/lpabon/vagrant-gfsm
sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
godbc.Check(sshexec != nil)
// Create volume
commands := []string{
cmd,
fmt.Sprintf("sudo gluster volume start %v", v.Info.Name),
}
_, err = sshexec.ConnectAndExec(nodename+":22", commands, nil)
if err != nil {
return err
}
// Setup mount point
v.Info.Mount = fmt.Sprintf("%v:%v", nodename, v.Info.Name)
// State
v.State.Created = true
v.State.Started = true
return nil
}
示例11: logread
func (c *Log) logread() {
defer c.wg.Done()
for m := range c.logreaders {
iopkt := m.IoPkt()
offset := c.offset(iopkt.LogBlock)
// Read from storage
start := time.Now()
n, err := c.fp.ReadAt(iopkt.Buffer, offset)
end := time.Now()
c.stats.ReadTimeRecord(end.Sub(start))
godbc.Check(n == len(iopkt.Buffer))
godbc.Check(err == nil)
c.stats.StorageHit()
// Save in buffer cache
//c.bc.Set(offset, iopkt.Buffer)
// Return to caller
m.Done()
}
}
示例12: NewTestApp
func NewTestApp(dbfile string) *App {
// Create simple configuration for unit tests
appConfig := bytes.NewBuffer([]byte(`{
"glusterfs" : {
"executor" : "mock",
"allocator" : "simple",
"db" : "` + dbfile + `"
}
}`))
app := NewApp(appConfig)
godbc.Check(app != nil)
return app
}
示例13: Destroy
func (b *BrickEntry) Destroy(db *bolt.DB, executor executors.Executor) error {
godbc.Require(db != nil)
godbc.Require(b.TpSize > 0)
godbc.Require(b.Info.Size > 0)
if b.State != BRICK_STATE_ONLINE {
return nil
}
// Get node hostname
var host string
err := db.View(func(tx *bolt.Tx) error {
node, err := NewNodeEntryFromId(tx, b.Info.NodeId)
if err != nil {
return err
}
host = node.ManageHostName()
godbc.Check(host != "")
return nil
})
if err != nil {
return err
}
// Create request
req := &executors.BrickRequest{}
req.Name = b.Info.Id
req.Size = b.Info.Size
req.TpSize = b.TpSize
req.VgId = b.Info.DeviceId
// Delete brick on node
logger.Info("Deleting brick %v", b.Info.Id)
err = executor.BrickDestroy(host, req)
if err != nil {
b.State = BRICK_STATE_FAILED
return err
}
b.State = BRICK_STATE_DELETED
godbc.Ensure(b.State == BRICK_STATE_DELETED)
return nil
}
示例14: Create
func (b *Brick) Create() error {
godbc.Require(b.db != nil)
godbc.Require(b.DeviceId != "")
// Just for now, it will work wih https://github.com/lpabon/vagrant-gfsm
sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
godbc.Check(sshexec != nil)
var nodename string
err := b.db.Reader(func() error {
nodename = b.db.nodes[b.NodeId].Info.Name
return nil
})
commands := []string{
fmt.Sprintf("sudo lvcreate -L %vKiB -T vg_%v/tp_%v -V %vKiB -n brick_%v",
//Thin Pool Size
uint64(float64(b.Size)*THINP_SNAPSHOT_FACTOR),
// volume group
b.DeviceId,
// ThinP name
b.Id,
// Volume size
b.Size,
// Logical Vol name
b.Id),
fmt.Sprintf("sudo mkfs.xfs -i size=512 /dev/vg_%v/brick_%v", b.DeviceId, b.Id),
fmt.Sprintf("sudo mkdir /gluster/brick_%v", b.Id),
fmt.Sprintf("sudo mount /dev/vg_%v/brick_%v /gluster/brick_%v",
b.DeviceId, b.Id, b.Id),
fmt.Sprintf("sudo mkdir /gluster/brick_%v/brick", b.Id),
}
_, err = sshexec.ConnectAndExec(nodename+":22", commands, nil)
if err != nil {
return err
}
// SSH into node and create brick
b.Path = fmt.Sprintf("/gluster/brick_%v", b.Id)
return nil
}
示例15: peerProbe
func (m *GlusterFSPlugin) peerProbe(name string) error {
// Just for now, it will work wih https://github.com/lpabon/vagrant-gfsm
sshexec := ssh.NewSshExecWithKeyFile("vagrant", "insecure_private_key")
godbc.Check(sshexec != nil)
// create the commands
commands := []string{
fmt.Sprintf("sudo gluster peer probe %v", name),
}
_, err := sshexec.ConnectAndExec(m.peerHost+":22", commands, nil)
if err != nil {
return err
}
return nil
}