Skip to content

Commit 7c51215

Browse files
author
Greg Soltis
authored
Port FSTListenSequence (#2322)
1 parent 5982981 commit 7c51215

File tree

6 files changed

+61
-99
lines changed

6 files changed

+61
-99
lines changed

Firestore/Source/Core/FSTListenSequence.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

Firestore/Source/Core/FSTListenSequence.mm

Lines changed: 0 additions & 52 deletions
This file was deleted.

Firestore/Source/Local/FSTLevelDB.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <utility>
2222

2323
#import "FIRFirestoreErrors.h"
24-
#import "Firestore/Source/Core/FSTListenSequence.h"
2524
#import "Firestore/Source/Local/FSTLRUGarbageCollector.h"
2625
#import "Firestore/Source/Local/FSTLevelDBMutationQueue.h"
2726
#import "Firestore/Source/Remote/FSTSerializerBeta.h"
@@ -35,6 +34,7 @@
3534
#include "Firestore/core/src/firebase/firestore/local/leveldb_remote_document_cache.h"
3635
#include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h"
3736
#include "Firestore/core/src/firebase/firestore/local/leveldb_util.h"
37+
#include "Firestore/core/src/firebase/firestore/local/listen_sequence.h"
3838
#include "Firestore/core/src/firebase/firestore/local/reference_set.h"
3939
#include "Firestore/core/src/firebase/firestore/local/remote_document_cache.h"
4040
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
@@ -66,6 +66,7 @@
6666
using firebase::firestore::local::LevelDbQueryCache;
6767
using firebase::firestore::local::LevelDbRemoteDocumentCache;
6868
using firebase::firestore::local::LevelDbTransaction;
69+
using firebase::firestore::local::ListenSequence;
6970
using firebase::firestore::local::LruParams;
7071
using firebase::firestore::local::ReferenceSet;
7172
using firebase::firestore::local::RemoteDocumentCache;
@@ -119,7 +120,8 @@ @implementation FSTLevelDBLRUDelegate {
119120
__weak FSTLevelDB *_db;
120121
ReferenceSet *_additionalReferences;
121122
ListenSequenceNumber _currentSequenceNumber;
122-
FSTListenSequence *_listenSequence;
123+
// PORTING NOTE: doesn't need to be a pointer once this class is ported to C++.
124+
std::unique_ptr<ListenSequence> _listenSequence;
123125
}
124126

125127
- (instancetype)initWithPersistence:(FSTLevelDB *)persistence lruParams:(LruParams)lruParams {
@@ -133,13 +135,13 @@ - (instancetype)initWithPersistence:(FSTLevelDB *)persistence lruParams:(LruPara
133135

134136
- (void)start {
135137
ListenSequenceNumber highestSequenceNumber = _db.queryCache->highest_listen_sequence_number();
136-
_listenSequence = [[FSTListenSequence alloc] initStartingAfter:highestSequenceNumber];
138+
_listenSequence = absl::make_unique<ListenSequence>(highestSequenceNumber);
137139
}
138140

139141
- (void)transactionWillStart {
140142
HARD_ASSERT(_currentSequenceNumber == kFSTListenSequenceNumberInvalid,
141143
"Previous sequence number is still in effect");
142-
_currentSequenceNumber = [_listenSequence next];
144+
_currentSequenceNumber = _listenSequence->Next();
143145
}
144146

145147
- (void)transactionWillCommit {

Firestore/Source/Local/FSTLocalStore.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <utility>
2222

2323
#import "FIRTimestamp.h"
24-
#import "Firestore/Source/Core/FSTListenSequence.h"
2524
#import "Firestore/Source/Core/FSTQuery.h"
2625
#import "Firestore/Source/Local/FSTLRUGarbageCollector.h"
2726
#import "Firestore/Source/Local/FSTLocalDocumentsView.h"

Firestore/Source/Local/FSTMemoryPersistence.mm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#include <unordered_set>
2222
#include <vector>
2323

24-
#import "Firestore/Source/Core/FSTListenSequence.h"
2524
#import "Firestore/Source/Local/FSTMemoryMutationQueue.h"
2625
#include "absl/memory/memory.h"
2726

2827
#include "Firestore/core/src/firebase/firestore/auth/user.h"
28+
#include "Firestore/core/src/firebase/firestore/local/listen_sequence.h"
2929
#include "Firestore/core/src/firebase/firestore/local/memory_query_cache.h"
3030
#include "Firestore/core/src/firebase/firestore/local/memory_remote_document_cache.h"
3131
#include "Firestore/core/src/firebase/firestore/local/reference_set.h"
@@ -34,6 +34,7 @@
3434

3535
using firebase::firestore::auth::HashUser;
3636
using firebase::firestore::auth::User;
37+
using firebase::firestore::local::ListenSequence;
3738
using firebase::firestore::local::LruParams;
3839
using firebase::firestore::local::MemoryQueryCache;
3940
using firebase::firestore::local::MemoryRemoteDocumentCache;
@@ -161,7 +162,8 @@ @implementation FSTMemoryLRUReferenceDelegate {
161162
std::unordered_map<DocumentKey, ListenSequenceNumber, DocumentKeyHash> _sequenceNumbers;
162163
ReferenceSet *_additionalReferences;
163164
FSTLRUGarbageCollector *_gc;
164-
FSTListenSequence *_listenSequence;
165+
// PORTING NOTE: when this class is ported to C++, this does not need to be a pointer
166+
std::unique_ptr<ListenSequence> _listenSequence;
165167
ListenSequenceNumber _currentSequenceNumber;
166168
FSTLocalSerializer *_serializer;
167169
}
@@ -176,7 +178,7 @@ - (instancetype)initWithPersistence:(FSTMemoryPersistence *)persistence
176178
// Theoretically this is always 0, since this is all in-memory...
177179
ListenSequenceNumber highestSequenceNumber =
178180
_persistence.queryCache->highest_listen_sequence_number();
179-
_listenSequence = [[FSTListenSequence alloc] initStartingAfter:highestSequenceNumber];
181+
_listenSequence = absl::make_unique<ListenSequence>(highestSequenceNumber);
180182
_serializer = serializer;
181183
}
182184
return self;
@@ -210,7 +212,7 @@ - (void)limboDocumentUpdated:(const DocumentKey &)key {
210212
}
211213

212214
- (void)startTransaction:(absl::string_view)label {
213-
_currentSequenceNumber = [_listenSequence next];
215+
_currentSequenceNumber = _listenSequence->Next();
214216
}
215217

216218
- (void)commitTransaction {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2019 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_LISTEN_SEQUENCE_H_
18+
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_LISTEN_SEQUENCE_H_
19+
20+
#include "Firestore/core/src/firebase/firestore/model/types.h"
21+
22+
namespace firebase {
23+
namespace firestore {
24+
namespace local {
25+
26+
/**
27+
* ListenSequence is a monotonic sequence. It is initialized with a minimum
28+
* value to exceed. All subsequent calls to next will return increasing values.
29+
*/
30+
class ListenSequence {
31+
public:
32+
explicit ListenSequence(model::ListenSequenceNumber starting_after)
33+
: previous_sequence_number_(starting_after) {
34+
}
35+
36+
model::ListenSequenceNumber Next() {
37+
previous_sequence_number_++;
38+
return previous_sequence_number_;
39+
}
40+
41+
private:
42+
model::ListenSequenceNumber previous_sequence_number_;
43+
};
44+
45+
} // namespace local
46+
} // namespace firestore
47+
} // namespace firebase
48+
49+
#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_LISTEN_SEQUENCE_H_

0 commit comments

Comments
 (0)