Class: Omnizip::Parity::ChunkedBlockProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/parity/chunked_block_processor.rb

Overview

Chunked block processor for incremental Reed-Solomon recovery

Implements correct RS decoding: x = A^-1 * b where b = recovery - sum(present * base[present[k]]^exponent)

Processes large blocks incrementally in memory-efficient chunks.

Constant Summary collapse

DEFAULT_CHUNK_SIZE =

Default chunk size (1MB)

1024 * 1024

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matrix, present_blocks, recovery_blocks, missing_indices, block_size, chunk_size: DEFAULT_CHUNK_SIZE) ⇒ ChunkedBlockProcessor

Initialize processor

Parameters:

  • matrix (ReedSolomonMatrix)

    Precomputed RS matrix (A^-1)

  • present_blocks (Hash<Integer, String>)

    Present data blocks

  • recovery_blocks (Hash<Integer, String>)

    Recovery blocks (by exponent)

  • missing_indices (Array<Integer>)

    Indices to recover

  • block_size (Integer)

    Block size in bytes

  • chunk_size (Integer) (defaults to: DEFAULT_CHUNK_SIZE)

    Chunk size for processing



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 41

def initialize(matrix, present_blocks, recovery_blocks, missing_indices,
 block_size, chunk_size: DEFAULT_CHUNK_SIZE)
  @matrix = matrix
  @present_blocks = present_blocks
  @recovery_blocks = recovery_blocks
  @missing_indices = missing_indices.sort
  @block_size = block_size
  # Ensure chunk_size is even (we process 16-bit words)
  requested_chunk = [chunk_size, block_size].min
  @chunk_size = requested_chunk - (requested_chunk % 2)
end

Instance Attribute Details

#block_sizeInteger (readonly)

Returns Block size in bytes.

Returns:

  • (Integer)

    Block size in bytes



28
29
30
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 28

def block_size
  @block_size
end

#chunk_sizeInteger (readonly)

Returns Chunk size for processing.

Returns:

  • (Integer)

    Chunk size for processing



31
32
33
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 31

def chunk_size
  @chunk_size
end

#matrixReedSolomonMatrix (readonly)

Returns RS matrix with precomputed coefficients.

Returns:



16
17
18
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 16

def matrix
  @matrix
end

#missing_indicesArray<Integer> (readonly)

Returns Missing block indices to recover.

Returns:

  • (Array<Integer>)

    Missing block indices to recover



25
26
27
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 25

def missing_indices
  @missing_indices
end

#present_blocksHash<Integer, String> (readonly)

Returns Present input blocks (index => data).

Returns:

  • (Hash<Integer, String>)

    Present input blocks (index => data)



19
20
21
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 19

def present_blocks
  @present_blocks
end

#recovery_blocksHash<Integer, String> (readonly)

Returns Recovery blocks (exponent => data).

Returns:

  • (Hash<Integer, String>)

    Recovery blocks (exponent => data)



22
23
24
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 22

def recovery_blocks
  @recovery_blocks
end

Instance Method Details

#process_allHash<Integer, String>

Process all blocks incrementally

Implements: x = A^-1 * b where b = recovery - present_contributions

Returns:

  • (Hash<Integer, String>)

    Recovered blocks



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/omnizip/parity/chunked_block_processor.rb', line 59

def process_all
  # Initialize output blocks (all zeros)
  recovered = {}
  missing_indices.each do |idx|
    recovered[idx] = "\x00".b * block_size
  end

  # Process block chunk by chunk
  block_offset = 0
  while block_offset < block_size
    current_chunk_size = [chunk_size, block_size - block_offset].min
    process_chunk_at_offset(recovered, block_offset, current_chunk_size)
    block_offset += current_chunk_size
  end

  recovered
end