_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q32800 | IsTaskAllocated | train | func (na *cnmNetworkAllocator) IsTaskAllocated(t *api.Task) bool {
// If the task is not found in the allocated set, then it is
// not allocated.
if _, ok := na.tasks[t.ID]; !ok {
return false
}
// If Networks is empty there is no way this Task is allocated.
if len(t.Networks) == 0 {
return false
}
// To ... | go | {
"resource": ""
} |
q32801 | AllocateTask | train | func (na *cnmNetworkAllocator) AllocateTask(t *api.Task) error {
for i, nAttach := range t.Networks {
if localNet := na.getNetwork(nAttach.Network.ID); localNet != nil && localNet.isNodeLocal {
continue
}
if err := na.allocateNetworkIPs(nAttach); err != nil {
if err := na.releaseEndpoints(t.Networks[:i]); ... | go | {
"resource": ""
} |
q32802 | DeallocateTask | train | func (na *cnmNetworkAllocator) DeallocateTask(t *api.Task) error {
delete(na.tasks, t.ID)
return na.releaseEndpoints(t.Networks)
} | go | {
"resource": ""
} |
q32803 | IsAttachmentAllocated | train | func (na *cnmNetworkAllocator) IsAttachmentAllocated(node *api.Node, networkAttachment *api.NetworkAttachment) bool {
if node == nil {
return false
}
if networkAttachment == nil || networkAttachment.Network == nil {
return false
}
// If the node is not found in the allocated set, then it is
// not allocated... | go | {
"resource": ""
} |
q32804 | AllocateAttachment | train | func (na *cnmNetworkAllocator) AllocateAttachment(node *api.Node, networkAttachment *api.NetworkAttachment) error {
if err := na.allocateNetworkIPs(networkAttachment); err != nil {
return err
}
if na.nodes[node.ID] == nil {
na.nodes[node.ID] = make(map[string]struct{})
}
na.nodes[node.ID][networkAttachment.N... | go | {
"resource": ""
} |
q32805 | DeallocateAttachment | train | func (na *cnmNetworkAllocator) DeallocateAttachment(node *api.Node, networkAttachment *api.NetworkAttachment) error {
delete(na.nodes[node.ID], networkAttachment.Network.ID)
if len(na.nodes[node.ID]) == 0 {
delete(na.nodes, node.ID)
}
return na.releaseEndpoints([]*api.NetworkAttachment{networkAttachment})
} | go | {
"resource": ""
} |
q32806 | allocateVIP | train | func (na *cnmNetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
var opts map[string]string
localNet := na.getNetwork(vip.NetworkID)
if localNet == nil {
return errors.New("networkallocator: could not find local network state")
}
if localNet.isNodeLocal {
return nil
}
// If this IP is alread... | go | {
"resource": ""
} |
q32807 | allocateNetworkIPs | train | func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment) error {
var ip *net.IPNet
var opts map[string]string
ipam, _, _, err := na.resolveIPAM(nAttach.Network)
if err != nil {
return errors.Wrap(err, "failed to resolve IPAM while allocating")
}
localNet := na.getNetwork(nAttach.Netwo... | go | {
"resource": ""
} |
q32808 | resolveDriver | train | func (na *cnmNetworkAllocator) resolveDriver(n *api.Network) (*networkDriver, error) {
dName := DefaultDriver
if n.Spec.DriverConfig != nil && n.Spec.DriverConfig.Name != "" {
dName = n.Spec.DriverConfig.Name
}
d, drvcap := na.drvRegistry.Driver(dName)
if d == nil {
err := na.loadDriver(dName)
if err != nil... | go | {
"resource": ""
} |
q32809 | resolveIPAM | train | func (na *cnmNetworkAllocator) resolveIPAM(n *api.Network) (ipamapi.Ipam, string, map[string]string, error) {
dName := ipamapi.DefaultIPAM
if n.Spec.IPAM != nil && n.Spec.IPAM.Driver != nil && n.Spec.IPAM.Driver.Name != "" {
dName = n.Spec.IPAM.Driver.Name
}
var dOptions map[string]string
if n.Spec.IPAM != nil ... | go | {
"resource": ""
} |
q32810 | IsVIPOnIngressNetwork | train | func (na *cnmNetworkAllocator) IsVIPOnIngressNetwork(vip *api.Endpoint_VirtualIP) bool {
if vip == nil {
return false
}
localNet := na.getNetwork(vip.NetworkID)
if localNet != nil && localNet.nw != nil {
return networkallocator.IsIngressNetwork(localNet.nw)
}
return false
} | go | {
"resource": ""
} |
q32811 | IsBuiltInDriver | train | func IsBuiltInDriver(name string) bool {
n := strings.ToLower(name)
for _, d := range initializers {
if n == d.ntype {
return true
}
}
return false
} | go | {
"resource": ""
} |
q32812 | setIPAMSerialAlloc | train | func setIPAMSerialAlloc(opts map[string]string) map[string]string {
if opts == nil {
opts = make(map[string]string)
}
if _, ok := opts[ipamapi.AllocSerialPrefix]; !ok {
opts[ipamapi.AllocSerialPrefix] = "true"
}
return opts
} | go | {
"resource": ""
} |
q32813 | NewContext | train | func NewContext(n *api.NodeDescription, t *api.Task) (ctx Context) {
ctx.Service.ID = t.ServiceID
ctx.Service.Name = t.ServiceAnnotations.Name
ctx.Service.Labels = t.ServiceAnnotations.Labels
ctx.Node.ID = t.NodeID
// Add node information to context only if we have them available
if n != nil {
ctx.Node.Hostna... | go | {
"resource": ""
} |
q32814 | NewPayloadContextFromTask | train | func NewPayloadContextFromTask(node *api.NodeDescription, t *api.Task, dependencies exec.DependencyGetter) (ctx PayloadContext) {
return PayloadContext{
Context: NewContext(node, t),
t: t,
restrictedSecrets: secrets.Restrict(dependencies.Secrets(), t),
restrictedConfigs: configs.Restr... | go | {
"resource": ""
} |
q32815 | EventUpdate | train | func (r resourceEntry) EventUpdate(oldObject api.StoreObject) api.Event {
if oldObject != nil {
return api.EventUpdateResource{Resource: r.Resource, OldResource: oldObject.(resourceEntry).Resource}
}
return api.EventUpdateResource{Resource: r.Resource}
} | go | {
"resource": ""
} |
q32816 | CreateResource | train | func CreateResource(tx Tx, r *api.Resource) error {
if err := confirmExtension(tx, r); err != nil {
return err
}
// TODO(dperny): currently the "name" index is unique, which means only one
// Resource of _any_ Kind can exist with that name. This isn't a problem
// right now, but the ideal case would be for names... | go | {
"resource": ""
} |
q32817 | UpdateResource | train | func UpdateResource(tx Tx, r *api.Resource) error {
if err := confirmExtension(tx, r); err != nil {
return err
}
return tx.update(tableResource, resourceEntry{r})
} | go | {
"resource": ""
} |
q32818 | DeleteResource | train | func DeleteResource(tx Tx, id string) error {
return tx.delete(tableResource, id)
} | go | {
"resource": ""
} |
q32819 | GetResource | train | func GetResource(tx ReadTx, id string) *api.Resource {
r := tx.get(tableResource, id)
if r == nil {
return nil
}
return r.(resourceEntry).Resource
} | go | {
"resource": ""
} |
q32820 | FindResources | train | func FindResources(tx ReadTx, by By) ([]*api.Resource, error) {
checkType := func(by By) error {
switch by.(type) {
case byIDPrefix, byName, byNamePrefix, byKind, byCustom, byCustomPrefix:
return nil
default:
return ErrInvalidFindBy
}
}
resourceList := []*api.Resource{}
appendResult := func(o api.Sto... | go | {
"resource": ""
} |
q32821 | New | train | func New(config *Config) (*Agent, error) {
if err := config.validate(); err != nil {
return nil, err
}
a := &Agent{
config: config,
sessionq: make(chan sessionOperation),
started: make(chan struct{}),
leaving: make(chan struct{}),
left: make(chan struct{})... | go | {
"resource": ""
} |
q32822 | Start | train | func (a *Agent) Start(ctx context.Context) error {
err := errAgentStarted
a.startOnce.Do(func() {
close(a.started)
go a.run(ctx)
err = nil // clear error above, only once.
})
return err
} | go | {
"resource": ""
} |
q32823 | Leave | train | func (a *Agent) Leave(ctx context.Context) error {
select {
case <-a.started:
default:
return errAgentNotStarted
}
a.leaveOnce.Do(func() {
close(a.leaving)
})
// Do not call Wait until we have confirmed that the agent is no longer
// accepting assignments. Starting a worker might race with Wait.
select {... | go | {
"resource": ""
} |
q32824 | Stop | train | func (a *Agent) Stop(ctx context.Context) error {
select {
case <-a.started:
default:
return errAgentNotStarted
}
a.stop()
// wait till closed or context cancelled
select {
case <-a.closed:
return nil
case <-ctx.Done():
return ctx.Err()
}
} | go | {
"resource": ""
} |
q32825 | stop | train | func (a *Agent) stop() bool {
var stopped bool
a.stopOnce.Do(func() {
close(a.stopped)
stopped = true
})
return stopped
} | go | {
"resource": ""
} |
q32826 | Err | train | func (a *Agent) Err(ctx context.Context) error {
select {
case <-a.closed:
return a.err
case <-ctx.Done():
return ctx.Err()
}
} | go | {
"resource": ""
} |
q32827 | withSession | train | func (a *Agent) withSession(ctx context.Context, fn func(session *session) error) error {
response := make(chan error, 1)
select {
case a.sessionq <- sessionOperation{
fn: fn,
response: response,
}:
select {
case err := <-response:
return err
case <-a.closed:
return ErrClosed
case <-ctx.Done... | go | {
"resource": ""
} |
q32828 | UpdateTaskStatus | train | func (a *Agent) UpdateTaskStatus(ctx context.Context, taskID string, status *api.TaskStatus) error {
log.G(ctx).WithField("task.id", taskID).Debug("(*Agent).UpdateTaskStatus")
ctx, cancel := context.WithCancel(ctx)
defer cancel()
errs := make(chan error, 1)
if err := a.withSession(ctx, func(session *session) erro... | go | {
"resource": ""
} |
q32829 | Publisher | train | func (a *Agent) Publisher(ctx context.Context, subscriptionID string) (exec.LogPublisher, func(), error) {
// TODO(stevvooe): The level of coordination here is WAY too much for logs.
// These should only be best effort and really just buffer until a session is
// ready. Ideally, they would use a separate connection ... | go | {
"resource": ""
} |
q32830 | nodeDescriptionWithHostname | train | func (a *Agent) nodeDescriptionWithHostname(ctx context.Context, tlsInfo *api.NodeTLSInfo) (*api.NodeDescription, error) {
desc, err := a.config.Executor.Describe(ctx)
// Override hostname and TLS info
if desc != nil {
if a.config.Hostname != "" && desc != nil {
desc.Hostname = a.config.Hostname
}
desc.TLS... | go | {
"resource": ""
} |
q32831 | nodesEqual | train | func nodesEqual(a, b *api.Node) bool {
a, b = a.Copy(), b.Copy()
a.Status, b.Status = api.NodeStatus{}, api.NodeStatus{}
a.Meta, b.Meta = api.Meta{}, api.Meta{}
return reflect.DeepEqual(a, b)
} | go | {
"resource": ""
} |
q32832 | IsTemporary | train | func IsTemporary(err error) bool {
for err != nil {
if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
return true
}
cause := errors.Cause(err)
if cause == err {
break
}
err = cause
}
return false
} | go | {
"resource": ""
} |
q32833 | LogTLSState | train | func LogTLSState(ctx context.Context, tlsState *tls.ConnectionState) {
if tlsState == nil {
log.G(ctx).Debugf("no TLS Chains found")
return
}
peerCerts := []string{}
verifiedChain := []string{}
for _, cert := range tlsState.PeerCertificates {
peerCerts = append(peerCerts, cert.Subject.CommonName)
}
for _,... | go | {
"resource": ""
} |
q32834 | getCertificateSubject | train | func getCertificateSubject(tlsState *tls.ConnectionState) (pkix.Name, error) {
if tlsState == nil {
return pkix.Name{}, status.Errorf(codes.PermissionDenied, "request is not using TLS")
}
if len(tlsState.PeerCertificates) == 0 {
return pkix.Name{}, status.Errorf(codes.PermissionDenied, "no client certificates in... | go | {
"resource": ""
} |
q32835 | certSubjectFromContext | train | func certSubjectFromContext(ctx context.Context) (pkix.Name, error) {
connState, err := tlsConnStateFromContext(ctx)
if err != nil {
return pkix.Name{}, err
}
return getCertificateSubject(connState)
} | go | {
"resource": ""
} |
q32836 | AuthorizeOrgAndRole | train | func AuthorizeOrgAndRole(ctx context.Context, org string, blacklistedCerts map[string]*api.BlacklistedCertificate, ou ...string) (string, error) {
certSubj, err := certSubjectFromContext(ctx)
if err != nil {
return "", err
}
// Check if the current certificate has an OU that authorizes
// access to this method
... | go | {
"resource": ""
} |
q32837 | authorizeOrg | train | func authorizeOrg(certSubj pkix.Name, org string, blacklistedCerts map[string]*api.BlacklistedCertificate) (string, error) {
if _, ok := blacklistedCerts[certSubj.CommonName]; ok {
return "", status.Errorf(codes.PermissionDenied, "Permission denied: node %s was removed from swarm", certSubj.CommonName)
}
if len(c... | go | {
"resource": ""
} |
q32838 | AuthorizeForwardedRoleAndOrg | train | func AuthorizeForwardedRoleAndOrg(ctx context.Context, authorizedRoles, forwarderRoles []string, org string, blacklistedCerts map[string]*api.BlacklistedCertificate) (string, error) {
if isForwardedRequest(ctx) {
_, err := AuthorizeOrgAndRole(ctx, org, blacklistedCerts, forwarderRoles...)
if err != nil {
return... | go | {
"resource": ""
} |
q32839 | intersectArrays | train | func intersectArrays(orig, tgt []string) bool {
for _, i := range orig {
for _, x := range tgt {
if i == x {
return true
}
}
}
return false
} | go | {
"resource": ""
} |
q32840 | RemoteNode | train | func RemoteNode(ctx context.Context) (RemoteNodeInfo, error) {
// If we have a value on the context that marks this as a local
// request, we return the node info from the context.
localNodeInfo := ctx.Value(LocalRequestKey)
if localNodeInfo != nil {
nodeInfo, ok := localNodeInfo.(RemoteNodeInfo)
if ok {
re... | go | {
"resource": ""
} |
q32841 | NewSupervisor | train | func NewSupervisor(store *store.MemoryStore) *Supervisor {
return &Supervisor{
store: store,
delays: make(map[string]*delayedStart),
historyByService: make(map[string]map[orchestrator.SlotTuple]*instanceRestartInfo),
TaskTimeout: defaultOldTaskTimeout,
}
} | go | {
"resource": ""
} |
q32842 | UpdatableTasksInSlot | train | func (r *Supervisor) UpdatableTasksInSlot(ctx context.Context, slot orchestrator.Slot, service *api.Service) orchestrator.Slot {
if len(slot) < 1 {
return nil
}
var updatable orchestrator.Slot
for _, t := range slot {
if t.DesiredState <= api.TaskStateRunning {
updatable = append(updatable, t)
}
}
if le... | go | {
"resource": ""
} |
q32843 | RecordRestartHistory | train | func (r *Supervisor) RecordRestartHistory(tuple orchestrator.SlotTuple, replacementTask *api.Task) {
if replacementTask.Spec.Restart == nil || replacementTask.Spec.Restart.MaxAttempts == 0 {
// No limit on the number of restarts, so no need to record
// history.
return
}
r.mu.Lock()
defer r.mu.Unlock()
ser... | go | {
"resource": ""
} |
q32844 | StartNow | train | func (r *Supervisor) StartNow(tx store.Tx, taskID string) error {
t := store.GetTask(tx, taskID)
if t == nil || t.DesiredState >= api.TaskStateRunning {
return nil
}
t.DesiredState = api.TaskStateRunning
return store.UpdateTask(tx, t)
} | go | {
"resource": ""
} |
q32845 | Cancel | train | func (r *Supervisor) Cancel(taskID string) {
r.mu.Lock()
delay, ok := r.delays[taskID]
r.mu.Unlock()
if !ok {
return
}
delay.cancel()
<-delay.doneCh
} | go | {
"resource": ""
} |
q32846 | CancelAll | train | func (r *Supervisor) CancelAll() {
var cancelled []delayedStart
r.mu.Lock()
for _, delay := range r.delays {
delay.cancel()
}
r.mu.Unlock()
for _, delay := range cancelled {
<-delay.doneCh
}
} | go | {
"resource": ""
} |
q32847 | ClearServiceHistory | train | func (r *Supervisor) ClearServiceHistory(serviceID string) {
r.mu.Lock()
delete(r.historyByService, serviceID)
r.mu.Unlock()
} | go | {
"resource": ""
} |
q32848 | NewCluster | train | func NewCluster() *Cluster {
// TODO(abronan): generate Cluster ID for federation
return &Cluster{
members: make(map[uint64]*Member),
removed: make(map[uint64]bool),
PeersBroadcast: watch.NewQueue(),
}
} | go | {
"resource": ""
} |
q32849 | Members | train | func (c *Cluster) Members() map[uint64]*Member {
members := make(map[uint64]*Member)
c.mu.RLock()
for k, v := range c.members {
members[k] = v
}
c.mu.RUnlock()
return members
} | go | {
"resource": ""
} |
q32850 | Removed | train | func (c *Cluster) Removed() []uint64 {
c.mu.RLock()
removed := make([]uint64, 0, len(c.removed))
for k := range c.removed {
removed = append(removed, k)
}
c.mu.RUnlock()
return removed
} | go | {
"resource": ""
} |
q32851 | GetMember | train | func (c *Cluster) GetMember(id uint64) *Member {
c.mu.RLock()
defer c.mu.RUnlock()
return c.members[id]
} | go | {
"resource": ""
} |
q32852 | AddMember | train | func (c *Cluster) AddMember(member *Member) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[member.RaftID] {
return ErrIDRemoved
}
c.members[member.RaftID] = member
c.broadcastUpdate()
return nil
} | go | {
"resource": ""
} |
q32853 | RemoveMember | train | func (c *Cluster) RemoveMember(id uint64) error {
c.mu.Lock()
defer c.mu.Unlock()
c.removed[id] = true
return c.clearMember(id)
} | go | {
"resource": ""
} |
q32854 | UpdateMember | train | func (c *Cluster) UpdateMember(id uint64, m *api.RaftMember) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[id] {
return ErrIDRemoved
}
oldMember, ok := c.members[id]
if !ok {
return ErrIDNotFound
}
if oldMember.NodeID != m.NodeID {
// Should never happen; this is a sanity check
return errors.N... | go | {
"resource": ""
} |
q32855 | ClearMember | train | func (c *Cluster) ClearMember(id uint64) error {
c.mu.Lock()
defer c.mu.Unlock()
return c.clearMember(id)
} | go | {
"resource": ""
} |
q32856 | IsIDRemoved | train | func (c *Cluster) IsIDRemoved(id uint64) bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.removed[id]
} | go | {
"resource": ""
} |
q32857 | Clear | train | func (c *Cluster) Clear() {
c.mu.Lock()
c.members = make(map[uint64]*Member)
c.removed = make(map[uint64]bool)
c.mu.Unlock()
} | go | {
"resource": ""
} |
q32858 | ValidateConfigurationChange | train | func (c *Cluster) ValidateConfigurationChange(cc raftpb.ConfChange) error {
c.mu.Lock()
defer c.mu.Unlock()
if c.removed[cc.NodeID] {
return ErrIDRemoved
}
switch cc.Type {
case raftpb.ConfChangeAddNode:
if c.members[cc.NodeID] != nil {
return ErrIDExists
}
case raftpb.ConfChangeRemoveNode:
if c.memb... | go | {
"resource": ""
} |
q32859 | Unlock | train | func (m *timedMutex) Unlock() {
unlockedTimestamp := m.lockedAt.Load()
m.lockedAt.Store(time.Time{})
m.Mutex.Unlock()
lockedFor := time.Since(unlockedTimestamp.(time.Time))
storeLockDurationTimer.Update(lockedFor)
} | go | {
"resource": ""
} |
q32860 | NewMemoryStore | train | func NewMemoryStore(proposer state.Proposer) *MemoryStore {
memDB, err := memdb.NewMemDB(schema)
if err != nil {
// This shouldn't fail
panic(err)
}
return &MemoryStore{
memDB: memDB,
queue: watch.NewQueue(),
proposer: proposer,
}
} | go | {
"resource": ""
} |
q32861 | View | train | func (s *MemoryStore) View(cb func(ReadTx)) {
defer metrics.StartTimer(viewLatencyTimer)()
memDBTx := s.memDB.Txn(false)
readTx := readTx{
memDBTx: memDBTx,
}
cb(readTx)
memDBTx.Commit()
} | go | {
"resource": ""
} |
q32862 | changelistBetweenVersions | train | func (s *MemoryStore) changelistBetweenVersions(from, to api.Version) ([]api.Event, error) {
if s.proposer == nil {
return nil, errors.New("store does not support versioning")
}
changes, err := s.proposer.ChangesBetween(from, to)
if err != nil {
return nil, err
}
var changelist []api.Event
for _, change :=... | go | {
"resource": ""
} |
q32863 | ApplyStoreActions | train | func (s *MemoryStore) ApplyStoreActions(actions []api.StoreAction) error {
s.updateLock.Lock()
memDBTx := s.memDB.Txn(true)
tx := tx{
readTx: readTx{
memDBTx: memDBTx,
},
}
for _, sa := range actions {
if err := applyStoreAction(&tx, sa); err != nil {
memDBTx.Abort()
s.updateLock.Unlock()
retur... | go | {
"resource": ""
} |
q32864 | Update | train | func (batch *Batch) Update(cb func(Tx) error) error {
if batch.err != nil {
return batch.err
}
if err := cb(&batch.tx); err != nil {
return err
}
batch.applied++
for batch.changelistLen < len(batch.tx.changelist) {
sa, err := api.NewStoreAction(batch.tx.changelist[batch.changelistLen])
if err != nil {
... | go | {
"resource": ""
} |
q32865 | Batch | train | func (s *MemoryStore) Batch(cb func(*Batch) error) error {
defer metrics.StartTimer(batchLatencyTimer)()
s.updateLock.Lock()
batch := Batch{
store: s,
}
batch.newTx()
if err := cb(&batch); err != nil {
batch.tx.memDBTx.Abort()
s.updateLock.Unlock()
return err
}
err := batch.commit()
s.updateLock.Unl... | go | {
"resource": ""
} |
q32866 | lookup | train | func (tx readTx) lookup(table, index, id string) api.StoreObject {
defer metrics.StartTimer(lookupLatencyTimer)()
j, err := tx.memDBTx.First(table, index, id)
if err != nil {
return nil
}
if j != nil {
return j.(api.StoreObject)
}
return nil
} | go | {
"resource": ""
} |
q32867 | create | train | func (tx *tx) create(table string, o api.StoreObject) error {
if tx.lookup(table, indexID, o.GetID()) != nil {
return ErrExist
}
copy := o.CopyStoreObject()
meta := copy.GetMeta()
if err := touchMeta(&meta, tx.curVersion); err != nil {
return err
}
copy.SetMeta(meta)
err := tx.memDBTx.Insert(table, copy)
... | go | {
"resource": ""
} |
q32868 | update | train | func (tx *tx) update(table string, o api.StoreObject) error {
oldN := tx.lookup(table, indexID, o.GetID())
if oldN == nil {
return ErrNotExist
}
meta := o.GetMeta()
if tx.curVersion != nil {
if oldN.GetMeta().Version != meta.Version {
return ErrSequenceConflict
}
}
copy := o.CopyStoreObject()
if err... | go | {
"resource": ""
} |
q32869 | delete | train | func (tx *tx) delete(table, id string) error {
n := tx.lookup(table, indexID, id)
if n == nil {
return ErrNotExist
}
err := tx.memDBTx.Delete(table, n)
if err == nil {
tx.changelist = append(tx.changelist, n.EventDelete())
}
return err
} | go | {
"resource": ""
} |
q32870 | get | train | func (tx readTx) get(table, id string) api.StoreObject {
o := tx.lookup(table, indexID, id)
if o == nil {
return nil
}
return o.CopyStoreObject()
} | go | {
"resource": ""
} |
q32871 | find | train | func (tx readTx) find(table string, by By, checkType func(By) error, appendResult func(api.StoreObject)) error {
fromResultIterators := func(its ...memdb.ResultIterator) {
ids := make(map[string]struct{})
for _, it := range its {
for {
obj := it.Next()
if obj == nil {
break
}
o := obj.(api.... | go | {
"resource": ""
} |
q32872 | Save | train | func (s *MemoryStore) Save(tx ReadTx) (*pb.StoreSnapshot, error) {
var snapshot pb.StoreSnapshot
for _, os := range objectStorers {
if err := os.Save(tx, &snapshot); err != nil {
return nil, err
}
}
return &snapshot, nil
} | go | {
"resource": ""
} |
q32873 | Restore | train | func (s *MemoryStore) Restore(snapshot *pb.StoreSnapshot) error {
return s.updateLocal(func(tx Tx) error {
for _, os := range objectStorers {
if err := os.Restore(tx, snapshot); err != nil {
return err
}
}
return nil
})
} | go | {
"resource": ""
} |
q32874 | ViewAndWatch | train | func ViewAndWatch(store *MemoryStore, cb func(ReadTx) error, specifiers ...api.Event) (watch chan events.Event, cancel func(), err error) {
// Using Update to lock the store and guarantee consistency between
// the watcher and the the state seen by the callback. snapshotReadTx
// exposes this Tx as a ReadTx so the c... | go | {
"resource": ""
} |
q32875 | touchMeta | train | func touchMeta(meta *api.Meta, version *api.Version) error {
// Skip meta update if version is not defined as it means we're applying
// from raft or restoring from a snapshot.
if version == nil {
return nil
}
now, err := gogotypes.TimestampProto(time.Now())
if err != nil {
return err
}
meta.Version = *ve... | go | {
"resource": ""
} |
q32876 | Wedged | train | func (s *MemoryStore) Wedged() bool {
lockedAt := s.updateLock.LockedAt()
if lockedAt.IsZero() {
return false
}
return time.Since(lockedAt) > WedgeTimeout
} | go | {
"resource": ""
} |
q32877 | NewTemplatedSecretGetter | train | func NewTemplatedSecretGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.SecretGetter {
return templatedSecretGetter{dependencies: dependencies, t: t, node: node}
} | go | {
"resource": ""
} |
q32878 | NewTemplatedConfigGetter | train | func NewTemplatedConfigGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) TemplatedConfigGetter {
return templatedConfigGetter{dependencies: dependencies, t: t, node: node}
} | go | {
"resource": ""
} |
q32879 | NewTemplatedDependencyGetter | train | func NewTemplatedDependencyGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.DependencyGetter {
return templatedDependencyGetter{
secrets: NewTemplatedSecretGetter(dependencies, t, node),
configs: NewTemplatedConfigGetter(dependencies, t, node),
}
} | go | {
"resource": ""
} |
q32880 | BootstrapNew | train | func (e *EncryptedRaftLogger) BootstrapNew(metadata []byte) error {
e.encoderMu.Lock()
defer e.encoderMu.Unlock()
encrypter, decrypter := encryption.Defaults(e.EncryptionKey, e.FIPS)
walFactory := NewWALFactory(encrypter, decrypter)
for _, dirpath := range []string{filepath.Dir(e.walDir()), e.snapDir()} {
if er... | go | {
"resource": ""
} |
q32881 | RotateEncryptionKey | train | func (e *EncryptedRaftLogger) RotateEncryptionKey(newKey []byte) {
e.encoderMu.Lock()
defer e.encoderMu.Unlock()
if e.wal != nil { // if the wal exists, the snapshotter exists
// We don't want to have to close the WAL, because we can't open a new one.
// We need to know the previous snapshot, because when you o... | go | {
"resource": ""
} |
q32882 | SaveSnapshot | train | func (e *EncryptedRaftLogger) SaveSnapshot(snapshot raftpb.Snapshot) error {
walsnap := walpb.Snapshot{
Index: snapshot.Metadata.Index,
Term: snapshot.Metadata.Term,
}
e.encoderMu.RLock()
if err := e.wal.SaveSnapshot(walsnap); err != nil {
e.encoderMu.RUnlock()
return err
}
snapshotter := e.snapshotte... | go | {
"resource": ""
} |
q32883 | GC | train | func (e *EncryptedRaftLogger) GC(index uint64, term uint64, keepOldSnapshots uint64) error {
// Delete any older snapshots
curSnapshot := fmt.Sprintf("%016x-%016x%s", term, index, ".snap")
snapshots, err := ListSnapshots(e.snapDir())
if err != nil {
return err
}
// Ignore any snapshots that are older than the... | go | {
"resource": ""
} |
q32884 | SaveEntries | train | func (e *EncryptedRaftLogger) SaveEntries(st raftpb.HardState, entries []raftpb.Entry) error {
e.encoderMu.RLock()
defer e.encoderMu.RUnlock()
if e.wal == nil {
return fmt.Errorf("raft WAL has either been closed or has never been created")
}
return e.wal.Save(st, entries)
} | go | {
"resource": ""
} |
q32885 | Close | train | func (e *EncryptedRaftLogger) Close(ctx context.Context) {
e.encoderMu.Lock()
defer e.encoderMu.Unlock()
if e.wal != nil {
if err := e.wal.Close(); err != nil {
log.G(ctx).WithError(err).Error("error closing raft WAL")
}
}
e.wal = nil
e.snapshotter = nil
} | go | {
"resource": ""
} |
q32886 | Clear | train | func (e *EncryptedRaftLogger) Clear(ctx context.Context) error {
e.encoderMu.Lock()
defer e.encoderMu.Unlock()
if e.wal != nil {
if err := e.wal.Close(); err != nil {
log.G(ctx).WithError(err).Error("error closing raft WAL")
}
}
e.snapshotter = nil
os.RemoveAll(e.walDir())
os.RemoveAll(e.snapDir())
ret... | go | {
"resource": ""
} |
q32887 | Init | train | func (w *worker) Init(ctx context.Context) error {
w.mu.Lock()
defer w.mu.Unlock()
ctx = log.WithModule(ctx, "worker")
// TODO(stevvooe): Start task cleanup process.
// read the tasks from the database and start any task managers that may be needed.
return w.db.Update(func(tx *bolt.Tx) error {
return WalkTas... | go | {
"resource": ""
} |
q32888 | Close | train | func (w *worker) Close() {
w.mu.Lock()
w.closed = true
w.mu.Unlock()
w.taskevents.Close()
} | go | {
"resource": ""
} |
q32889 | Assign | train | func (w *worker) Assign(ctx context.Context, assignments []*api.AssignmentChange) error {
w.mu.Lock()
defer w.mu.Unlock()
if w.closed {
return ErrClosed
}
log.G(ctx).WithFields(logrus.Fields{
"len(assignments)": len(assignments),
}).Debug("(*worker).Assign")
// Need to update dependencies before tasks
e... | go | {
"resource": ""
} |
q32890 | updateTaskStatus | train | func (w *worker) updateTaskStatus(ctx context.Context, tx *bolt.Tx, taskID string, status *api.TaskStatus) error {
if err := PutTaskStatus(tx, taskID, status); err != nil {
log.G(ctx).WithError(err).Error("failed writing status to disk")
return err
}
// broadcast the task status out.
for key := range w.listene... | go | {
"resource": ""
} |
q32891 | Subscribe | train | func (w *worker) Subscribe(ctx context.Context, subscription *api.SubscriptionMessage) error {
log.G(ctx).Debugf("Received subscription %s (selector: %v)", subscription.ID, subscription.Selector)
publisher, cancel, err := w.publisherProvider.Publisher(ctx, subscription.ID)
if err != nil {
return err
}
// Send a... | go | {
"resource": ""
} |
q32892 | ReadDir | train | func (a Afero) ReadDir(dirname string) ([]os.FileInfo, error) {
return ReadDir(a.Fs, dirname)
} | go | {
"resource": ""
} |
q32893 | ReadFile | train | func (a Afero) ReadFile(filename string) ([]byte, error) {
return ReadFile(a.Fs, filename)
} | go | {
"resource": ""
} |
q32894 | readAll | train | func readAll(r io.Reader, capacity int64) (b []byte, err error) {
buf := bytes.NewBuffer(make([]byte, 0, capacity))
// If the buffer overflows, we will get bytes.ErrTooLarge.
// Return that as an error. Any other panic remains.
defer func() {
e := recover()
if e == nil {
return
}
if panicErr, ok := e.(er... | go | {
"resource": ""
} |
q32895 | WriteFile | train | func (a Afero) WriteFile(filename string, data []byte, perm os.FileMode) error {
return WriteFile(a.Fs, filename, data, perm)
} | go | {
"resource": ""
} |
q32896 | WriteReader | train | func (a Afero) WriteReader(path string, r io.Reader) (err error) {
return WriteReader(a.Fs, path, r)
} | go | {
"resource": ""
} |
q32897 | GetTempDir | train | func GetTempDir(fs Fs, subPath string) string {
addSlash := func(p string) string {
if FilePathSeparator != p[len(p)-1:] {
p = p + FilePathSeparator
}
return p
}
dir := addSlash(os.TempDir())
if subPath != "" {
// preserve windows backslash :-(
if FilePathSeparator == "\\" {
subPath = strings.Repla... | go | {
"resource": ""
} |
q32898 | UnicodeSanitize | train | func UnicodeSanitize(s string) string {
source := []rune(s)
target := make([]rune, 0, len(source))
for _, r := range source {
if unicode.IsLetter(r) ||
unicode.IsDigit(r) ||
unicode.IsMark(r) ||
r == '.' ||
r == '/' ||
r == '\\' ||
r == '_' ||
r == '-' ||
r == '%' ||
r == ' ' ||
r ==... | go | {
"resource": ""
} |
q32899 | NeuterAccents | train | func NeuterAccents(s string) string {
t := transform.Chain(norm.NFD, transform.RemoveFunc(isMn), norm.NFC)
result, _, _ := transform.String(t, string(s))
return result
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.