func (p *MemoryPersistence) Delete(client string, direction dirFlag, uid uuid.UUID) bool { //only need to get a read lock on the persistence store, but lock the underlying //persistenceentry for the client we're working with. p.RLock() defer p.RUnlock() //checks that there is actually an entry for the message id we're being asked to //delete, if there isn't return false, otherwise delete the entry. id := uid.String() DEBUG.Println("Removing persisted message for", client) switch direction { case INBOUND: p.inbound[client].Lock() defer p.inbound[client].Unlock() //if there is already an entry for this message id return false if _, ok := p.inbound[client].messages[id]; !ok { return false } delete(p.inbound[client].messages, id) case OUTBOUND: p.outbound[client].Lock() defer p.outbound[client].Unlock() //if there is already an entry for this message id return false if _, ok := p.outbound[client].messages[id]; !ok { return false } delete(p.outbound[client].messages, id) } return true }
func (bs *BlockStore) LoadSuperblock(id uuid.UUID, generation uint64) *Superblock { var sb = fake_sblock{} if generation == LatestGeneration { //log.Info("loading superblock uuid=%v (lgen)", id.String()) qry := bs.db.C("superblocks").Find(bson.M{"uuid": id.String()}) if err := qry.Sort("-gen").One(&sb); err != nil { if err == mgo.ErrNotFound { lg.Info("sb notfound!") return nil } else { lg.Panic(err) } } } else { qry := bs.db.C("superblocks").Find(bson.M{"uuid": id.String(), "gen": generation}) if err := qry.One(&sb); err != nil { if err == mgo.ErrNotFound { return nil } else { lg.Panic(err) } } } rv := Superblock{ uuid: id, gen: sb.Gen, root: sb.Root, unlinked: sb.Unlinked, } return &rv }
func (db *InMemDatabase) GetByUuid(id uuid.UUID) (contrail.IObject, error) { uid := makeUID(id) obj, ok := db.objByIdMap[uid] if !ok { return nil, fmt.Errorf("%s: Not found", id.String()) } return obj, nil }
func newPod(h *Host, id uuid.UUID) *Pod { if id == nil { id = uuid.NewRandom() } return &Pod{ Host: h, UUID: id, ui: ui.NewUI("yellow", "pod", id.String()), } }
func NewImage(h *Host, id uuid.UUID) *Image { if id == nil { id = uuid.NewRandom() } return &Image{ Host: h, UUID: id, Manifest: *schema.BlankImageManifest(), ui: ui.NewUI("blue", "image", id.String()), } }
func (bs *BlockStore) UnlinkGenerations(id uuid.UUID, sgen uint64, egen uint64) error { iter := bs.db.C("superblocks").Find(bson.M{"uuid": id.String(), "gen": bson.M{"$gte": sgen, "$lt": egen}, "unlinked": false}).Iter() rs := fake_sblock{} for iter.Next(&rs) { rs.Unlinked = true _, err := bs.db.C("superblocks").Upsert(bson.M{"uuid": id.String(), "gen": rs.Gen}, rs) if err != nil { lg.Panic(err) } } return nil }
func (bs *BlockStore) DEBUG_DELETE_UUID(id uuid.UUID) { lg.Info("DEBUG removing uuid '%v' from database", id.String()) _, err := bs.db.C("superblocks").RemoveAll(bson.M{"uuid": id.String()}) if err != nil && err != mgo.ErrNotFound { lg.Panic(err) } if err == mgo.ErrNotFound { lg.Info("Quey did not find supeblock to delete") } else { lg.Info("err was nik") } //bs.datablockBarrier() }
/* * This obtains a generation, blocking if necessary */ func (bs *BlockStore) ObtainGeneration(id uuid.UUID) *Generation { //The first thing we do is obtain a write lock on the UUID, as a generation //represents a lock mk := UUIDToMapKey(id) bs.glock.RLock() mtx, ok := bs._wlocks[mk] bs.glock.RUnlock() if !ok { //Mutex doesn't exist so is unlocked mtx := new(sync.Mutex) mtx.Lock() bs.glock.Lock() bs._wlocks[mk] = mtx bs.glock.Unlock() } else { mtx.Lock() } gen := &Generation{ cblocks: make([]*Coreblock, 0, 8192), vblocks: make([]*Vectorblock, 0, 8192), } //We need a generation. Lets see if one is on disk qry := bs.db.C("superblocks").Find(bson.M{"uuid": id.String()}) rs := fake_sblock{} qerr := qry.Sort("-gen").One(&rs) if qerr == mgo.ErrNotFound { lg.Info("no superblock found for %v", id.String()) //Ok just create a new superblock/generation gen.Cur_SB = NewSuperblock(id) } else if qerr != nil { //Well thats more serious lg.Panic("Mongodb error: %v", qerr) } else { //Ok we have a superblock, pop the gen //log.Info("Found a superblock for %v", id.String()) sb := Superblock{ uuid: id, root: rs.Root, gen: rs.Gen, } gen.Cur_SB = &sb } gen.New_SB = gen.Cur_SB.Clone() gen.New_SB.gen = gen.Cur_SB.gen + 1 gen.blockstore = bs return gen }
func new_peer(uuid uuid.UUID) (peer *peer_t) { peer = &peer_t{ uuid_bytes: []byte(uuid), uuid_string: uuid.String(), } return }
// Get get build data func (r *LocalFsRegistry) Get(id uuid.UUID) (schema.Build, error) { // TODO: add error handling.(Expired Data and Not Found File) file, err := os.Open(r.dir + id.String() + ".json") if err != nil { return schema.Build{}, err } defer file.Close() var build schema.Build err = json.NewDecoder(file).Decode(&build) if err != nil { return schema.Build{}, err } return build, nil }
func (r *EtcdRegistry) Get(id uuid.UUID) (schema.Build, error) { key := path.Join(r.keyPrefix, id.String()) res, err := r.etcd.Get(key, false, true) if err != nil { return schema.Build{}, err } var build schema.Build err = unmarshal(res.Node.Value, &build) if err != nil { if isKeyNotFound(err) { // TODO (spesnova): return 404 error return schema.Build{}, err } return schema.Build{}, err } return build, nil }
//get time.Time form uuid code func getTime(uucode uuid.UUID) time.Time { ut, _ := uucode.Time() s, n := ut.UnixTime() return time.Unix(s, n) }