From 73e5007fe640e0ab4e1328dcd49b21a3b7400419 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:14:36 -0800 Subject: [PATCH 1/3] update proto, and add to ts file --- packages/firestore/src/protos.json | 1 + .../src/protos/firestore_proto_api.ts | 11 +++ .../google/firestore/v1/bloom_filter.proto | 73 +++++++++++++++++++ .../google/firestore/v1/firestore.proto | 10 +++ .../protos/google/firestore/v1/write.proto | 15 ++++ 5 files changed, 110 insertions(+) create mode 100644 packages/firestore/src/protos.json create mode 100644 packages/firestore/src/protos/google/firestore/v1/bloom_filter.proto diff --git a/packages/firestore/src/protos.json b/packages/firestore/src/protos.json new file mode 100644 index 00000000000..9e26dfeeb6e --- /dev/null +++ b/packages/firestore/src/protos.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/packages/firestore/src/protos/firestore_proto_api.ts b/packages/firestore/src/protos/firestore_proto_api.ts index e7dfe0a88b2..de01ea00c7d 100644 --- a/packages/firestore/src/protos/firestore_proto_api.ts +++ b/packages/firestore/src/protos/firestore_proto_api.ts @@ -224,6 +224,16 @@ export declare namespace firestoreV1ApiClientInterfaces { interface ExistenceFilter { targetId?: number; count?: number; + unchangedNames: BloomFilter; + } + interface BloomFilter { + bits?: BitSequence; + hasCount?: number; + } + + interface BitSequence { + bitmap?: string; + padding?: number; } interface FieldFilter { field?: FieldReference; @@ -382,6 +392,7 @@ export declare namespace firestoreV1ApiClientInterfaces { readTime?: Timestamp; targetId?: number; once?: boolean; + expectedCount?: number | { value: number }; } interface TargetChange { targetChangeType?: TargetChangeTargetChangeType; diff --git a/packages/firestore/src/protos/google/firestore/v1/bloom_filter.proto b/packages/firestore/src/protos/google/firestore/v1/bloom_filter.proto new file mode 100644 index 00000000000..6f3b70d4650 --- /dev/null +++ b/packages/firestore/src/protos/google/firestore/v1/bloom_filter.proto @@ -0,0 +1,73 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.firestore.v1; + +option csharp_namespace = "Google.Cloud.Firestore.V1"; +option go_package = "google.golang.org/genproto/googleapis/firestore/v1;firestore"; +option java_multiple_files = true; +option java_outer_classname = "BloomFilterProto"; +option java_package = "com.google.firestore.v1"; +option objc_class_prefix = "GCFS"; +option php_namespace = "Google\\Cloud\\Firestore\\V1"; +option ruby_package = "Google::Cloud::Firestore::V1"; + +// A sequence of bits, encoded in a byte array. +// +// Each byte in the `bitmap` byte array stores 8 bits of the sequence. The only +// exception is the last byte, which may store 8 _or fewer_ bits. The `padding` +// defines the number of bits of the last byte to be ignored as "padding". The +// values of these "padding" bits are unspecified and must be ignored. +// +// To retrieve the first bit, bit 0, calculate: (bitmap[0] & 0x01) != 0. +// To retrieve the second bit, bit 1, calculate: (bitmap[0] & 0x02) != 0. +// To retrieve the third bit, bit 2, calculate: (bitmap[0] & 0x04) != 0. +// To retrieve the fourth bit, bit 3, calculate: (bitmap[0] & 0x08) != 0. +// To retrieve bit n, calculate: (bitmap[n / 8] & (0x01 << (n % 8))) != 0. +// +// The "size" of a `BitSequence` (the number of bits it contains) is calculated +// by this formula: (bitmap.length * 8) - padding. +message BitSequence { + // The bytes that encode the bit sequence. + // May have a length of zero. + bytes bitmap = 1; + + // The number of bits of the last byte in `bitmap` to ignore as "padding". + // If the length of `bitmap` is zero, then this value must be 0. + // Otherwise, this value must be between 0 and 7, inclusive. + int32 padding = 2; +} + +// A bloom filter (https://en.wikipedia.org/wiki/Bloom_filter). +// +// The bloom filter hashes the entries with MD5 and treats the resulting 128-bit +// hash as 2 distinct 64-bit hash values, interpreted as unsigned integers +// using 2's complement encoding. +// +// These two hash values, named h1 and h2, are then used to compute the +// `hash_count` hash values using the formula, starting at i=0: +// +// h(i) = h1 + (i * h2) +// +// These resulting values are then taken modulo the number of bits in the bloom +// filter to get the bits of the bloom filter to test for the given entry. +message BloomFilter { + // The bloom filter data. + BitSequence bits = 1; + + // The number of hashes used by the algorithm. + int32 hash_count = 2; +} diff --git a/packages/firestore/src/protos/google/firestore/v1/firestore.proto b/packages/firestore/src/protos/google/firestore/v1/firestore.proto index aefbe71699f..63b497026bc 100644 --- a/packages/firestore/src/protos/google/firestore/v1/firestore.proto +++ b/packages/firestore/src/protos/google/firestore/v1/firestore.proto @@ -26,6 +26,7 @@ import "google/firestore/v1/query.proto"; import "google/firestore/v1/write.proto"; import "google/protobuf/empty.proto"; import "google/protobuf/timestamp.proto"; +import "google/protobuf/wrappers.proto"; import "google/rpc/status.proto"; option csharp_namespace = "Google.Cloud.Firestore.V1"; @@ -857,6 +858,15 @@ message Target { // If the target should be removed once it is current and consistent. bool once = 6; + + // The number of documents that last matched the query at the resume token or + // read time. + // + // This value is only relevant when a `resume_type` is provided. This value + // being present and greater than zero signals that the client wants + // `ExistenceFilter.unchanged_names` to be included in the response. + // + google.protobuf.Int32Value expected_count = 12; } // Targets being watched have changed. diff --git a/packages/firestore/src/protos/google/firestore/v1/write.proto b/packages/firestore/src/protos/google/firestore/v1/write.proto index a9ac9832de4..e0b87212844 100644 --- a/packages/firestore/src/protos/google/firestore/v1/write.proto +++ b/packages/firestore/src/protos/google/firestore/v1/write.proto @@ -16,6 +16,7 @@ syntax = "proto3"; package google.firestore.v1; +import "google/firestore/v1/bloom_filter.proto"; import "google/firestore/v1/common.proto"; import "google/firestore/v1/document.proto"; import "google/protobuf/timestamp.proto"; @@ -261,4 +262,18 @@ message ExistenceFilter { // If different from the count of documents in the client that match, the // client must manually determine which documents no longer match the target. int32 count = 2; + + // A bloom filter that contains the UTF-8 byte encodings of the resource names + // of the documents that match [target_id][], in the form + // `projects/{project_id}/databases/{database_id}/documents/{document_path}` + // that have NOT changed since the query results indicated by the resume token + // or timestamp given in `Target.resume_type`. + // + // This bloom filter may be omitted at the server's discretion, such as if it + // is deemed that the client will not make use of it or if it is too + // computationally expensive to calculate or transmit. Clients must gracefully + // handle this field being absent by falling back to the logic used before + // this field existed; that is, re-add the target without a resume token to + // figure out which documents in the client's cache are out of sync. + BloomFilter unchanged_names = 3; } From 35f51773edcc6e09e515e39e6b36cd33425a44ba Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:43:20 -0800 Subject: [PATCH 2/3] change typo --- packages/firestore/src/protos.json | 1 - packages/firestore/src/protos/firestore_proto_api.ts | 5 ++--- .../firestore/src/protos/google/firestore/v1/write.proto | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 packages/firestore/src/protos.json diff --git a/packages/firestore/src/protos.json b/packages/firestore/src/protos.json deleted file mode 100644 index 9e26dfeeb6e..00000000000 --- a/packages/firestore/src/protos.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/packages/firestore/src/protos/firestore_proto_api.ts b/packages/firestore/src/protos/firestore_proto_api.ts index de01ea00c7d..7cc76ff7ea9 100644 --- a/packages/firestore/src/protos/firestore_proto_api.ts +++ b/packages/firestore/src/protos/firestore_proto_api.ts @@ -224,13 +224,12 @@ export declare namespace firestoreV1ApiClientInterfaces { interface ExistenceFilter { targetId?: number; count?: number; - unchangedNames: BloomFilter; + unchangedNames?: BloomFilter; } interface BloomFilter { bits?: BitSequence; - hasCount?: number; + hashCount?: number; } - interface BitSequence { bitmap?: string; padding?: number; diff --git a/packages/firestore/src/protos/google/firestore/v1/write.proto b/packages/firestore/src/protos/google/firestore/v1/write.proto index e0b87212844..0778dff6863 100644 --- a/packages/firestore/src/protos/google/firestore/v1/write.proto +++ b/packages/firestore/src/protos/google/firestore/v1/write.proto @@ -264,8 +264,8 @@ message ExistenceFilter { int32 count = 2; // A bloom filter that contains the UTF-8 byte encodings of the resource names - // of the documents that match [target_id][], in the form - // `projects/{project_id}/databases/{database_id}/documents/{document_path}` + // of the documents that match [target_id][google.firestore.v1.ExistenceFilter.target_id], in the + // form `projects/{project_id}/databases/{database_id}/documents/{document_path}` // that have NOT changed since the query results indicated by the resume token // or timestamp given in `Target.resume_type`. // From 97f00549f95f6d6c54ad3cb246fd441527bb80b1 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Mon, 14 Nov 2022 14:01:18 -0800 Subject: [PATCH 3/3] Update firestore_proto_api.ts --- packages/firestore/src/protos/firestore_proto_api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/firestore/src/protos/firestore_proto_api.ts b/packages/firestore/src/protos/firestore_proto_api.ts index 7cc76ff7ea9..e07d147c2b2 100644 --- a/packages/firestore/src/protos/firestore_proto_api.ts +++ b/packages/firestore/src/protos/firestore_proto_api.ts @@ -231,7 +231,7 @@ export declare namespace firestoreV1ApiClientInterfaces { hashCount?: number; } interface BitSequence { - bitmap?: string; + bitmap?: string | Uint8Array; padding?: number; } interface FieldFilter { @@ -391,7 +391,7 @@ export declare namespace firestoreV1ApiClientInterfaces { readTime?: Timestamp; targetId?: number; once?: boolean; - expectedCount?: number | { value: number }; + expectedCount?: number; } interface TargetChange { targetChangeType?: TargetChangeTargetChangeType;