Next: , Previous: , Up: Bucket   [Contents][Index]


3.2 Bucket Diff

Changes to the bucket are represented by an array with certain conventions:

  1. A change to some index k is represented by the same index k in the diff.
  2. A value of undefined indicates that the respective index has not changed. Holes in the array (indexes not assigned any value) are treated in the same manner as undefined.
  3. A null in the last index of the vector marks a truncation point; it is used to delete one or more indexes. The vector will be truncated at that point. Any preceding null values are treated as if they were undefined.3

Diffs are only tracked at the vector (array of scalars) level—if there is a change to a nested structure assigned to an index, that index of the outer vector will be tracked as modified. It will, however, recursively compare nested changes to determine if a modification has taken place.4 Examples appear in Figure 3.1.

OriginalDiffInterpretation
["foo", "bar"]["baz", "quux"]Index 0 changed to ‘baz’. Index 1 changed to ‘quux’.
["foo", "bar"][undefined, "quux"]Index 0 did not change. Index 1 changed to ‘quux’.
["foo", "bar"][, "quux"]Index 0 did not change. Index 1 changed to ‘quux’.
["foo", "bar"]["baz", null]Index 0 changed to ‘baz’. Index 1 was removed.
["foo", "bar", "baz"][undefined, null]Index 0 was not changed. Index 1 was removed. Index 2 was removed.
["foo", "bar", "baz"][null, undefined, null]Index 0 was not changed. Index 1 was not changed. Index 2 was removed.
["foo", "bar", "baz"][null, null, null]Index 0 was not changed. Index 1 was not changed. Index 2 was removed.

Figure 3.1: Bucket diff examples.

Diffs are generated by StagingBucket. null truncation is understood both by StagingBucket and by QuoteDataBucket. A diff is applied to the underlying bucket by invoking StagingBucket#commit.


Footnotes

(3)

The reason for this seemingly redundant (and inconvenient) choice is that JSON encodes undefined values as null. Consequently, when serializing a diff, undefineds are lost. To address this, any null that is not in the tail position is treated as undefined. We cannot truncate at the first null, because ‘[null,null,null]’ may actually represent ‘[undefined,undefined,null]’.

(4)

See StagingBucket method #_parseChanges.


Next: , Previous: , Up: Bucket   [Contents][Index]