func applyLeaseCreate(le lease.Lessor, lc *pb.LeaseCreateRequest) (*pb.LeaseCreateResponse, error) { l, err := le.Grant(lease.LeaseID(lc.ID), lc.TTL) resp := &pb.LeaseCreateResponse{} if err == nil { resp.ID = int64(l.ID) resp.TTL = l.TTL } return resp, err }
func applyLeaseGrant(lessor lease.Lessor, req *etcdserverpb.LeaseGrantRequest) (*etcdserverpb.LeaseGrantResponse, error) { l, err := lessor.Grant(lease.LeaseID(req.ID), req.TTL) resp := &etcdserverpb.LeaseGrantResponse{} if err == nil { resp.ID = int64(l.ID) resp.TTL = l.TTL } return resp, err }
func checkRequestLeases(le lease.Lessor, reqs []*pb.RequestUnion) error { for _, requ := range reqs { preq := requ.RequestPut if preq == nil || lease.LeaseID(preq.Lease) == lease.NoLease { continue } if l := le.Lookup(lease.LeaseID(preq.Lease)); l == nil { return lease.ErrLeaseNotFound } } return nil }
func checkRequestLeases(le lease.Lessor, reqs []*etcdserverpb.RequestUnion) error { for _, requ := range reqs { tv, ok := requ.Request.(*etcdserverpb.RequestUnion_RequestPut) if !ok { continue } preq := tv.RequestPut if preq == nil || lease.LeaseID(preq.Lease) == lease.NoLease { continue } if l := le.Lookup(lease.LeaseID(preq.Lease)); l == nil { return lease.ErrLeaseNotFound } } return nil }
func applyPut(txnID int64, kv dstorage.KV, le lease.Lessor, p *pb.PutRequest) (*pb.PutResponse, error) { resp := &pb.PutResponse{} resp.Header = &pb.ResponseHeader{} var ( rev int64 err error ) if txnID != noTxn { rev, err = kv.TxnPut(txnID, p.Key, p.Value, lease.LeaseID(p.Lease)) if err != nil { return nil, err } } else { leaseID := lease.LeaseID(p.Lease) if leaseID != lease.NoLease { if l := le.Lookup(leaseID); l == nil { return nil, lease.ErrLeaseNotFound } } rev = kv.Put(p.Key, p.Value, leaseID) } resp.Header.Revision = rev return resp, nil }
func applyPut(txnID int64, kv mvcc.KV, lessor lease.Lessor, req *etcdserverpb.PutRequest) (*etcdserverpb.PutResponse, error) { resp := &etcdserverpb.PutResponse{} resp.Header = &etcdserverpb.ResponseHeader{} var ( rev int64 err error ) if txnID != noTxn { rev, err = kv.TxnPut(txnID, req.Key, req.Value, lease.LeaseID(req.Lease)) if err != nil { return nil, err } } else { leaseID := lease.LeaseID(req.Lease) if leaseID != lease.NoLease { if l := lessor.Lookup(leaseID); l == nil { return nil, lease.ErrLeaseNotFound } } rev = kv.Put(req.Key, req.Value, leaseID) } resp.Header.Revision = rev return resp, nil }
func applyLeaseRevoke(le lease.Lessor, lc *pb.LeaseRevokeRequest) (*pb.LeaseRevokeResponse, error) { err := le.Revoke(lease.LeaseID(lc.ID)) return &pb.LeaseRevokeResponse{}, err }
func applyLeaseCreate(le lease.Lessor, lc *pb.LeaseCreateRequest) (*pb.LeaseCreateResponse, error) { l := le.Grant(lc.TTL) return &pb.LeaseCreateResponse{ID: int64(l.ID), TTL: l.TTL}, nil }
func applyLeaseRevoke(lessor lease.Lessor, req *etcdserverpb.LeaseRevokeRequest) (*etcdserverpb.LeaseRevokeResponse, error) { err := lessor.Revoke(lease.LeaseID(req.ID)) return &etcdserverpb.LeaseRevokeResponse{}, err }