Skip to content

Commit

Permalink
Port FSTListenSequence (#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Soltis authored Jan 29, 2019
1 parent 5982981 commit 7c51215
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 99 deletions.
38 changes: 0 additions & 38 deletions Firestore/Source/Core/FSTListenSequence.h

This file was deleted.

52 changes: 0 additions & 52 deletions Firestore/Source/Core/FSTListenSequence.mm

This file was deleted.

10 changes: 6 additions & 4 deletions Firestore/Source/Local/FSTLevelDB.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <utility>

#import "FIRFirestoreErrors.h"
#import "Firestore/Source/Core/FSTListenSequence.h"
#import "Firestore/Source/Local/FSTLRUGarbageCollector.h"
#import "Firestore/Source/Local/FSTLevelDBMutationQueue.h"
#import "Firestore/Source/Remote/FSTSerializerBeta.h"
Expand All @@ -35,6 +34,7 @@
#include "Firestore/core/src/firebase/firestore/local/leveldb_remote_document_cache.h"
#include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h"
#include "Firestore/core/src/firebase/firestore/local/leveldb_util.h"
#include "Firestore/core/src/firebase/firestore/local/listen_sequence.h"
#include "Firestore/core/src/firebase/firestore/local/reference_set.h"
#include "Firestore/core/src/firebase/firestore/local/remote_document_cache.h"
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
Expand Down Expand Up @@ -66,6 +66,7 @@
using firebase::firestore::local::LevelDbQueryCache;
using firebase::firestore::local::LevelDbRemoteDocumentCache;
using firebase::firestore::local::LevelDbTransaction;
using firebase::firestore::local::ListenSequence;
using firebase::firestore::local::LruParams;
using firebase::firestore::local::ReferenceSet;
using firebase::firestore::local::RemoteDocumentCache;
Expand Down Expand Up @@ -119,7 +120,8 @@ @implementation FSTLevelDBLRUDelegate {
__weak FSTLevelDB *_db;
ReferenceSet *_additionalReferences;
ListenSequenceNumber _currentSequenceNumber;
FSTListenSequence *_listenSequence;
// PORTING NOTE: doesn't need to be a pointer once this class is ported to C++.
std::unique_ptr<ListenSequence> _listenSequence;
}

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

- (void)start {
ListenSequenceNumber highestSequenceNumber = _db.queryCache->highest_listen_sequence_number();
_listenSequence = [[FSTListenSequence alloc] initStartingAfter:highestSequenceNumber];
_listenSequence = absl::make_unique<ListenSequence>(highestSequenceNumber);
}

- (void)transactionWillStart {
HARD_ASSERT(_currentSequenceNumber == kFSTListenSequenceNumberInvalid,
"Previous sequence number is still in effect");
_currentSequenceNumber = [_listenSequence next];
_currentSequenceNumber = _listenSequence->Next();
}

- (void)transactionWillCommit {
Expand Down
1 change: 0 additions & 1 deletion Firestore/Source/Local/FSTLocalStore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <utility>

#import "FIRTimestamp.h"
#import "Firestore/Source/Core/FSTListenSequence.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Local/FSTLRUGarbageCollector.h"
#import "Firestore/Source/Local/FSTLocalDocumentsView.h"
Expand Down
10 changes: 6 additions & 4 deletions Firestore/Source/Local/FSTMemoryPersistence.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#include <unordered_set>
#include <vector>

#import "Firestore/Source/Core/FSTListenSequence.h"
#import "Firestore/Source/Local/FSTMemoryMutationQueue.h"
#include "absl/memory/memory.h"

#include "Firestore/core/src/firebase/firestore/auth/user.h"
#include "Firestore/core/src/firebase/firestore/local/listen_sequence.h"
#include "Firestore/core/src/firebase/firestore/local/memory_query_cache.h"
#include "Firestore/core/src/firebase/firestore/local/memory_remote_document_cache.h"
#include "Firestore/core/src/firebase/firestore/local/reference_set.h"
Expand All @@ -34,6 +34,7 @@

using firebase::firestore::auth::HashUser;
using firebase::firestore::auth::User;
using firebase::firestore::local::ListenSequence;
using firebase::firestore::local::LruParams;
using firebase::firestore::local::MemoryQueryCache;
using firebase::firestore::local::MemoryRemoteDocumentCache;
Expand Down Expand Up @@ -161,7 +162,8 @@ @implementation FSTMemoryLRUReferenceDelegate {
std::unordered_map<DocumentKey, ListenSequenceNumber, DocumentKeyHash> _sequenceNumbers;
ReferenceSet *_additionalReferences;
FSTLRUGarbageCollector *_gc;
FSTListenSequence *_listenSequence;
// PORTING NOTE: when this class is ported to C++, this does not need to be a pointer
std::unique_ptr<ListenSequence> _listenSequence;
ListenSequenceNumber _currentSequenceNumber;
FSTLocalSerializer *_serializer;
}
Expand All @@ -176,7 +178,7 @@ - (instancetype)initWithPersistence:(FSTMemoryPersistence *)persistence
// Theoretically this is always 0, since this is all in-memory...
ListenSequenceNumber highestSequenceNumber =
_persistence.queryCache->highest_listen_sequence_number();
_listenSequence = [[FSTListenSequence alloc] initStartingAfter:highestSequenceNumber];
_listenSequence = absl::make_unique<ListenSequence>(highestSequenceNumber);
_serializer = serializer;
}
return self;
Expand Down Expand Up @@ -210,7 +212,7 @@ - (void)limboDocumentUpdated:(const DocumentKey &)key {
}

- (void)startTransaction:(absl::string_view)label {
_currentSequenceNumber = [_listenSequence next];
_currentSequenceNumber = _listenSequence->Next();
}

- (void)commitTransaction {
Expand Down
49 changes: 49 additions & 0 deletions Firestore/core/src/firebase/firestore/local/listen_sequence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2019 Google
*
* 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.
*/

#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_LISTEN_SEQUENCE_H_
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_LISTEN_SEQUENCE_H_

#include "Firestore/core/src/firebase/firestore/model/types.h"

namespace firebase {
namespace firestore {
namespace local {

/**
* ListenSequence is a monotonic sequence. It is initialized with a minimum
* value to exceed. All subsequent calls to next will return increasing values.
*/
class ListenSequence {
public:
explicit ListenSequence(model::ListenSequenceNumber starting_after)
: previous_sequence_number_(starting_after) {
}

model::ListenSequenceNumber Next() {
previous_sequence_number_++;
return previous_sequence_number_;
}

private:
model::ListenSequenceNumber previous_sequence_number_;
};

} // namespace local
} // namespace firestore
} // namespace firebase

#endif // FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_LOCAL_LISTEN_SEQUENCE_H_

0 comments on commit 7c51215

Please sign in to comment.