Class: Wurk::Preflight::Keyspace

Inherits:
Object
  • Object
show all
Defined in:
lib/wurk/preflight/keyspace.rb

Overview

One SCAN pass over the keyspace, sorted into the families the checks ask about. A pass costs one round trip per COUNT keys and pauses between pages, so it never holds Redis, and stops at limit keys with truncated set: counts are then lower bounds and the report says so.

Constant Summary collapse

PAGE =
1000
PROGRESS_EVERY =
100_000
RETAINED =

Lists and batches kept for a closer look. Far above any real fleet's private lists; a keyspace with more has a bigger problem than this report.

10_000
SHA1_DIGEST =
/\A[0-9a-f]{40}\z/
SHA256_DIGEST =
/\A[0-9a-f]{64}\z/
GEM_LOCK =
/\Auniquejobs:[0-9a-f]{32}\z/
NAMESPACED_QUEUE =
/\A[^:|]+:queue:[^|]+\z/
BATCH_SUFFIX =
/-(?:#{Wurk::Batch::KEY_SUFFIXES.join('|')}|failinfo)\z/
COUNTED =
%w[private_lists batches unique_sha1 unique_sha256 unique_other gem_locks gem_keys
cron_entries namespaced_queues limiters].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reader, limit:, pause: 0.005, progress: nil) ⇒ Keyspace

Returns a new instance of Keyspace.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/wurk/preflight/keyspace.rb', line 30

def initialize(reader, limit:, pause: 0.005, progress: nil)
  @reader = reader
  @limit = limit
  @pause = pause
  @progress = progress
  @scanned = 0
  @truncated = false
  @counts = COUNTED.to_h { |name| [name, 0] }
  @private_lists = []
  @batches = []
end

Instance Attribute Details

#batches ⇒ Object (readonly)

Returns the value of attribute batches.



28
29
30
# File 'lib/wurk/preflight/keyspace.rb', line 28

def batches
  @batches
end

#counts ⇒ Object (readonly)

Returns the value of attribute counts.



28
29
30
# File 'lib/wurk/preflight/keyspace.rb', line 28

def counts
  @counts
end

#private_lists ⇒ Object (readonly)

Returns the value of attribute private_lists.



28
29
30
# File 'lib/wurk/preflight/keyspace.rb', line 28

def private_lists
  @private_lists
end

#scanned ⇒ Object (readonly)

Returns the value of attribute scanned.



28
29
30
# File 'lib/wurk/preflight/keyspace.rb', line 28

def scanned
  @scanned
end

Instance Method Details

#to_h ⇒ Object



58
59
60
# File 'lib/wurk/preflight/keyspace.rb', line 58

def to_h
  { 'keys_scanned' => @scanned, 'truncated' => @truncated }.merge(@counts)
end

#truncated? ⇒ Boolean

Returns:

  • (Boolean)


42
# File 'lib/wurk/preflight/keyspace.rb', line 42

def truncated? = @truncated

#walk ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/wurk/preflight/keyspace.rb', line 44

def walk
  cursor = '0'
  loop do
    cursor, keys = @reader.call('SCAN', cursor, 'COUNT', PAGE)
    keys.each { |key| classify(key) }
    report_progress(keys.size)
    break if cursor == '0'
    break @truncated = true if @scanned >= @limit

    sleep(@pause) if @pause.positive?
  end
  self
end