// expireData runs a delete operation on the storage engine.
//
// Any series data that (1) belongs to a bucket in the provided list and
// (2) falls outside the bucket's indicated retention period will be deleted.
182964
func (s *retentionEnforcer) expireData(ctx context.Context, buckets []*influxdb.Bucket, now time.Time) {
	logger, logEnd := logger.NewOperation(ctx, s.logger, "Data deletion", "data_deletion")
	defer logEnd()

	for _, b := range buckets {
		if b.RetentionPeriod == 0 {
			continue
		}

		span, _ := tracing.StartSpanFromContext(ctx)
		span.LogKV(
			"bucket", b.Name,
			"org_id", b.OrgID,
			"retention_period", b.RetentionPeriod,
			"retention_policy", b.RetentionPolicyName)

		max := now.Add(-b.RetentionPeriod).UnixNano()
		err := s.Engine.DeleteBucketRange(b.OrgID, b.ID, math.MinInt64, max)
		if err != nil {
			logger.Info("unable to delete bucket range",
				zap.String("bucket id", b.ID.String()),
				zap.String("org id", b.OrgID.String()),
				zap.Error(err))
			tracing.LogError(span, err)
		}
		s.tracker.IncChecks(b.OrgID, b.ID, err == nil)

		span.Finish()
	}
}
202444
func (c *Chain) IsExpired() bool {
	if c.curr != nil {
		return c.curr.IsExpired()
	}

	return true
}
958303
func (t *Token) expired() bool {
	if t.Expiry.IsZero() {
		return false
	}
	return t.Expiry.Add(-expiryDelta).Before(time.Now())
}
299511
func (s Storage) expirationDuration(c context.Context) time.Duration {
	if info.IsDevAppServer(c) {
		return time.Second
	}
	return time.Minute
}
945786
func (s *Session) Expired() error {
	if time.Now().After(s.ExpiresAt) {
		return fmt.Errorf(ErrSessionExpired)
	}

	return nil
}
1282016
func VerifyExpiry(s *data.SignedCommon, role data.RoleName) error {
	if IsExpired(s.Expires) {
		logrus.Errorf("Metadata for %s expired", role)
		return ErrExpired{Role: role, Expired: s.Expires.Format("Mon Jan 2 15:04:05 MST 2006")}
	}
	return nil
}
1300141
func (s *CacheService) IsExpired(base string) bool {
	// No cache? bail.
	if cache[base] == nil || (len(cache[base].Rates) <= 0) {
		return true
	}

	// Expired cache? bail.
	lastUpdated := cache[base].UpdatedAt
	if lastUpdated != nil && lastUpdated.Add(cacheTTL).Before(time.Now()) {
		return true
	}

	return false
}
1094529
func (o *pdOracle) IsExpired(lockTS, TTL uint64) bool {
	lastTS := atomic.LoadUint64(&o.lastTS)
	return oracle.ExtractPhysical(lastTS) >= oracle.ExtractPhysical(lockTS)+int64(TTL)
}
1031595
func (t *token) Expired() bool {
	if t == nil {
		return true
	}
	return !t.Token.Valid()
}
1028820
func (mj *Client) DeleteData(mdr *DataRequest) (err error) {
	url := buildDataURL(mj.apiBase, mdr)
	req, err := createRequest("DELETE", url, nil, nil)
	if err != nil {
		return err
	}

	_, _, err = mj.httpClient.Send(req).Call()

	return err
}
561932
func (s *PolicyComplianceDetail) SetExpiredAt(v time.Time) *PolicyComplianceDetail {
	s.ExpiredAt = &v
	return s
}
25739
func (t *notifyTarget) Expired(key lease.Key) {
	coll, closer := t.mongo.GetCollection(t.collection)
	defer closer()
	docId := leaseHolderDocId(key.Namespace, key.ModelUUID, key.Lease)
	t.log("expired %q", docId)
	err := t.mongo.RunTransaction(func(_ int) ([]txn.Op, error) {
		existingDoc, err := getRecord(coll, docId)
		if err == mgo.ErrNotFound {
			return nil, jujutxn.ErrNoOperations
		}
		if err != nil {
			return nil, errors.Trace(err)
		}
		return []txn.Op{{
			C:  t.collection,
			Id: docId,
			Assert: bson.M{
				fieldHolder: existingDoc.Holder,
			},
			Remove: true,
		}}, nil
	})

	if err != nil {
		t.errorLogger.Errorf("couldn't expire lease %q in db: %s", docId, err.Error())
		t.log("couldn't expire lease %q in db: %s", docId, err.Error())
		return
	}
}
244873
func (c *Client) ExpireAt(key string, timestamp int) (bool, error) {
	v, err := c.execWithKey(true, "EXPIREAT", key, timestamp)
	if err != nil {
		return false, err
	}
	return iface2bool(v)
}
1028235
func (p *TTLPolicy) IsExpired(obj *timestampedEntry) bool {
	return p.Ttl > 0 && p.Clock.Since(obj.timestamp) > p.Ttl
}
388517
func (a *Account) expiredTimeout() {
	// Collect the clients.
	a.mu.Lock()
	a.expired = true
	a.mu.Unlock()

	cs := make([]*client, 0, len(a.clients))
	a.mu.RLock()
	for c := range a.clients {
		cs = append(cs, c)
	}
	a.mu.RUnlock()

	for _, c := range cs {
		c.accountAuthExpired()
	}
}
1229461
func (self *TimedStore) getData(index int) timedStoreData {
	return self.buffer[len(self.buffer)-index-1]
}
645192
func (ttl *SnapshotTTL) Purge(age time.Duration) (time.Duration, error) {
	ctx := datastore.Get()
	defer ctx.Metrics().Stop(ctx.Metrics().Start("SnapshotTTL.Purge"))

	logger := plog.WithField("age", int(age.Minutes()))

	expire := time.Now().Add(-age)
	var tenantIDs []string
	var unused struct{}
	if err := ttl.client.GetTenantIDs(unused, &tenantIDs); err != nil {
		logger.WithError(err).Error("Could not look up tenantIDs")
		return 0, err
	}

	for _, tenantID := range tenantIDs {
		var snapshots []dao.SnapshotInfo
		if err := ttl.client.ListSnapshots(tenantID, &snapshots); err != nil {
			logger.WithField("tenantid", tenantID).
				WithError(err).Error("Could not look up snapshots for tenant service")
			return 0, err
		}
		for _, s := range snapshots {
			//ignore snapshots that have any tag
			if len(s.Tags) == 0 {
				// check the age of the snapshot
				if timeToLive := s.Created.Sub(expire); timeToLive <= 0 {
					snapshotLogger := logger.WithFields(log.Fields{
						"tenantid": tenantID,
						"snapshotid": s.SnapshotID,
					})
					if err := ttl.client.DeleteSnapshot(s.SnapshotID, nil); err != nil {
						snapshotLogger.WithError(err).Error("Could not delete snapshot")
						return 0, err
					}
					snapshotLogger.Debug("Deleted snapshot")
				} else if timeToLive < age {
					// set the new time to live based on the age of the
					// oldest non-expired snapshot.
					age = timeToLive
				}
			}
		}
	}
	logger.WithField("age", int(age.Minutes())).Debug("Finished Purge")

	return age, nil
}