示例#1
0
文件: server.go 项目: kr/doozerd
func (c *conn) walk(t *T, tx txn) {
	pat := pb.GetString(t.Path)
	glob, err := store.CompileGlob(pat)
	if err != nil {
		c.respond(t, Valid|Done, nil, errResponse(err))
		return
	}

	offset := pb.GetInt32(t.Offset)
	if offset < 0 {
		c.respond(t, Valid|Done, nil, erange)
		return
	}

	if g := c.getterFor(t); g != nil {
		var r R
		f := func(path, body string, rev int64) (stop bool) {
			if offset == 0 {
				r.Path = &path
				r.Value = []byte(body)
				r.Rev = &rev
				return true
			}
			offset--
			return false
		}
		if store.Walk(g, glob, f) {
			c.respond(t, Set|Valid|Done, nil, &r)
		} else {
			c.respond(t, Valid|Done, nil, erange)
		}
	}
}
示例#2
0
文件: member.go 项目: kr/doozer
func clearSlot(p consensus.Proposer, g store.Getter, name string) {
	store.Walk(g, calGlob, func(path, body string, rev int64) bool {
		if body == name {
			consensus.Set(p, path, nil, rev)
		}
		return false
	})
}
示例#3
0
func removeInfo(p paxos.Proposer, g store.Getter, name string) {
	ch, err := store.Walk(g, "/doozer/info/"+name+"/**")
	if err != nil {
		panic(err)
	}

	for ev := range ch {
		paxos.Del(p, ev.Path, ev.Cas)
	}
}
示例#4
0
文件: server.go 项目: kr/doozerd
func (sv *Server) cals() []string {
	cals := make([]string, 0)
	_, g := sv.St.Snap()
	store.Walk(g, calGlob, func(_, body string, _ int64) bool {
		if len(body) > 0 {
			cals = append(cals, body)
		}
		return false
	})
	return cals
}
示例#5
0
文件: member.go 项目: kr/doozer
func removeInfo(p consensus.Proposer, g store.Getter, name string) {
	glob, err := store.CompileGlob("/ctl/node/" + name + "/**")
	if err != nil {
		log.Println(err)
		return
	}
	store.Walk(g, glob, func(path, _ string, rev int64) bool {
		consensus.Del(p, path, rev)
		return false
	})
}
示例#6
0
func clearSlot(p paxos.Proposer, g store.Getter, name string) {
	ch, err := store.Walk(g, "/doozer/slot/*")
	if err != nil {
		panic(err)
	}

	for ev := range ch {
		if ev.Body == name {
			paxos.Set(p, ev.Path, "", ev.Cas)
		}
	}
}
示例#7
0
文件: lock.go 项目: kr/doozer
func Clean(p consensus.Proposer, ch <-chan store.Event) {
	for ev := range ch {
		if ev.IsDel() {
			name := ev.Path[len(SessDir)+1:]

			store.Walk(ev, locks, func(path, body string, rev int64) bool {
				if body == name {
					go consensus.Del(p, path, rev)
				}
				return false
			})
		}
	}
}
示例#8
0
文件: txn.go 项目: foamdino/doozerd
func (t *txn) walk() {
	if t.c.access == false {
		t.respondOsError(os.EACCES)
		return
	}

	if t.req.Path == nil || t.req.Offset == nil {
		t.respondErrCode(response_MISSING_ARG)
		return
	}

	glob, err := store.CompileGlob(*t.req.Path)
	if err != nil {
		t.respondOsError(err)
		return
	}

	offset := *t.req.Offset
	if offset < 0 {
		t.respondErrCode(response_RANGE)
		return
	}

	go func() {
		g, err := t.getter()
		if err != nil {
			t.respondOsError(err)
			return
		}

		f := func(path, body string, rev int64) (stop bool) {
			if offset == 0 {
				t.resp.Path = &path
				t.resp.Value = []byte(body)
				t.resp.Rev = &rev
				t.resp.Flags = proto.Int32(set)
				t.respond()
				return true
			}
			offset--
			return false
		}
		if !store.Walk(g, glob, f) {
			t.respondErrCode(response_RANGE)
		}
	}()
}
示例#9
0
func (c *conn) walk(t *T, tx txn) {
	pat := pb.GetString(t.Path)
	glob, err := store.CompileGlob(pat)
	if err != nil {
		c.respond(t, Valid|Done, nil, errResponse(err))
		return
	}

	offset := pb.GetInt32(t.Offset)

	var limit int32 = math.MaxInt32
	if t.Limit != nil {
		limit = pb.GetInt32(t.Limit)
	}

	if g := c.getterFor(t); g != nil {
		go func() {
			f := func(path, body string, rev int64) (stop bool) {
				select {
				case <-tx.cancel:
					c.closeTxn(*t.Tag)
					return true
				default:
				}

				if offset <= 0 && limit > 0 {
					var r R
					r.Path = &path
					r.Value = []byte(body)
					r.Rev = &rev
					c.respond(t, Valid|Set, tx.cancel, &r)

					limit--
				}

				offset--
				return false
			}

			stopped := store.Walk(g, glob, f)

			if !stopped {
				c.respond(t, Done, nil, &R{})
			}
		}()
	}
}
示例#10
0
func Clean(st *store.Store, pp paxos.Proposer) {
	logger := util.NewLogger("lock")
	for ev := range st.Watch("/session/*") {
		if !ev.IsDel() {
			continue
		}

		parts := strings.Split(ev.Path, "/", 3)
		name := parts[2]
		logger.Printf("lost session %s", name)

		ch, err := store.Walk(ev, "/lock/**")
		if err != nil {
			continue
		}

		for ev := range ch {
			if ev.Body == name {
				paxos.Del(pp, ev.Path, ev.Cas)
			}
		}
	}
}