diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-22 18:22:39 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-22 18:22:39 +0100 |
commit | b2ad8f785e801a35cadf254d827f56d648be510c (patch) | |
tree | 4eeb1e3eefb02c40dac40469c0fae5ad91feb3e3 | |
parent | 1fe8664ec74165fc3f250098609ea0e049e3adc8 (diff) | |
download | sink-b2ad8f785e801a35cadf254d827f56d648be510c.tar.gz sink-b2ad8f785e801a35cadf254d827f56d648be510c.zip |
Introduced Log::Context
To have hierarchical debug output we have to pass around something at
run-time, there is no reasonable alternative. Log::Context provides the
identifier to do just that and largely replaces the debug component
idea.
28 files changed, 181 insertions, 154 deletions
diff --git a/common/datastorequery.cpp b/common/datastorequery.cpp index de2d124..2a2f3f5 100644 --- a/common/datastorequery.cpp +++ b/common/datastorequery.cpp | |||
@@ -303,7 +303,7 @@ public: | |||
303 | }; | 303 | }; |
304 | 304 | ||
305 | DataStoreQuery::DataStoreQuery(const Sink::QueryBase &query, const QByteArray &type, EntityStore &store) | 305 | DataStoreQuery::DataStoreQuery(const Sink::QueryBase &query, const QByteArray &type, EntityStore &store) |
306 | : mQuery(query), mType(type), mStore(store) | 306 | : mQuery(query), mType(type), mStore(store), mLogCtx(store.logContext().subContext("datastorequery")) |
307 | { | 307 | { |
308 | setupQuery(); | 308 | setupQuery(); |
309 | } | 309 | } |
@@ -417,7 +417,7 @@ void DataStoreQuery::setupQuery() | |||
417 | for (const auto &k : baseFilters.keys()) { | 417 | for (const auto &k : baseFilters.keys()) { |
418 | const auto comparator = baseFilters.value(k); | 418 | const auto comparator = baseFilters.value(k); |
419 | if (comparator.value.canConvert<Query>()) { | 419 | if (comparator.value.canConvert<Query>()) { |
420 | SinkTrace() << "Executing subquery for property: " << k; | 420 | SinkTraceCtx(mLogCtx) << "Executing subquery for property: " << k; |
421 | const auto result = executeSubquery(comparator.value.value<Query>()); | 421 | const auto result = executeSubquery(comparator.value.value<Query>()); |
422 | baseFilters.insert(k, Query::Comparator(QVariant::fromValue(result), Query::Comparator::In)); | 422 | baseFilters.insert(k, Query::Comparator(QVariant::fromValue(result), Query::Comparator::In)); |
423 | } | 423 | } |
@@ -485,20 +485,20 @@ QVector<QByteArray> DataStoreQuery::loadIncrementalResultSet(qint64 baseRevision | |||
485 | mStore.readRevisions(baseRevision, mType, [&](const QByteArray &key) { | 485 | mStore.readRevisions(baseRevision, mType, [&](const QByteArray &key) { |
486 | changedKeys << key; | 486 | changedKeys << key; |
487 | }); | 487 | }); |
488 | SinkTrace() << "Finished reading incremental result set:" << *revisionCounter; | 488 | SinkTraceCtx(mLogCtx) << "Finished reading incremental result set:" << *revisionCounter; |
489 | return changedKeys; | 489 | return changedKeys; |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | ResultSet DataStoreQuery::update(qint64 baseRevision) | 493 | ResultSet DataStoreQuery::update(qint64 baseRevision) |
494 | { | 494 | { |
495 | SinkTrace() << "Executing query update"; | 495 | SinkTraceCtx(mLogCtx) << "Executing query update"; |
496 | auto incrementalResultSet = loadIncrementalResultSet(baseRevision); | 496 | auto incrementalResultSet = loadIncrementalResultSet(baseRevision); |
497 | SinkTrace() << "Changed: " << incrementalResultSet; | 497 | SinkTraceCtx(mLogCtx) << "Changed: " << incrementalResultSet; |
498 | mSource->add(incrementalResultSet); | 498 | mSource->add(incrementalResultSet); |
499 | ResultSet::ValueGenerator generator = [this](const ResultSet::Callback &callback) -> bool { | 499 | ResultSet::ValueGenerator generator = [this](const ResultSet::Callback &callback) -> bool { |
500 | if (mCollector->next([this, callback](const ResultSet::Result &result) { | 500 | if (mCollector->next([this, callback](const ResultSet::Result &result) { |
501 | SinkTrace() << "Got incremental result: " << result.entity.identifier() << result.operation; | 501 | SinkTraceCtx(mLogCtx) << "Got incremental result: " << result.entity.identifier() << result.operation; |
502 | callback(result); | 502 | callback(result); |
503 | })) | 503 | })) |
504 | { | 504 | { |
@@ -512,12 +512,12 @@ ResultSet DataStoreQuery::update(qint64 baseRevision) | |||
512 | 512 | ||
513 | ResultSet DataStoreQuery::execute() | 513 | ResultSet DataStoreQuery::execute() |
514 | { | 514 | { |
515 | SinkTrace() << "Executing query"; | 515 | SinkTraceCtx(mLogCtx) << "Executing query"; |
516 | 516 | ||
517 | ResultSet::ValueGenerator generator = [this](const ResultSet::Callback &callback) -> bool { | 517 | ResultSet::ValueGenerator generator = [this](const ResultSet::Callback &callback) -> bool { |
518 | if (mCollector->next([this, callback](const ResultSet::Result &result) { | 518 | if (mCollector->next([this, callback](const ResultSet::Result &result) { |
519 | if (result.operation != Sink::Operation_Removal) { | 519 | if (result.operation != Sink::Operation_Removal) { |
520 | SinkTrace() << "Got initial result: " << result.entity.identifier() << result.operation; | 520 | SinkTraceCtx(mLogCtx) << "Got initial result: " << result.entity.identifier() << result.operation; |
521 | callback(ResultSet::Result{result.entity, Sink::Operation_Creation, result.aggregateValues}); | 521 | callback(ResultSet::Result{result.entity, Sink::Operation_Creation, result.aggregateValues}); |
522 | } | 522 | } |
523 | })) | 523 | })) |
diff --git a/common/datastorequery.h b/common/datastorequery.h index 65503a8..a4c8c18 100644 --- a/common/datastorequery.h +++ b/common/datastorequery.h | |||
@@ -58,8 +58,7 @@ private: | |||
58 | QSharedPointer<Source> mSource; | 58 | QSharedPointer<Source> mSource; |
59 | 59 | ||
60 | Sink::Storage::EntityStore &mStore; | 60 | Sink::Storage::EntityStore &mStore; |
61 | 61 | Sink::Log::Context mLogCtx; | |
62 | SINK_DEBUG_COMPONENT(mType) | ||
63 | }; | 62 | }; |
64 | 63 | ||
65 | 64 | ||
diff --git a/common/facade.cpp b/common/facade.cpp index 4f03073..7f2da56 100644 --- a/common/facade.cpp +++ b/common/facade.cpp | |||
@@ -102,10 +102,10 @@ KAsync::Job<void> GenericFacade<DomainType>::remove(const DomainType &domainObje | |||
102 | } | 102 | } |
103 | 103 | ||
104 | template <class DomainType> | 104 | template <class DomainType> |
105 | QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> GenericFacade<DomainType>::load(const Sink::Query &query) | 105 | QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> GenericFacade<DomainType>::load(const Sink::Query &query, const Log::Context &ctx) |
106 | { | 106 | { |
107 | // The runner lives for the lifetime of the query | 107 | // The runner lives for the lifetime of the query |
108 | auto runner = new QueryRunner<DomainType>(query, mResourceContext, bufferTypeForDomainType()); | 108 | auto runner = new QueryRunner<DomainType>(query, mResourceContext, bufferTypeForDomainType(), ctx); |
109 | runner->setResultTransformation(mResultTransformation); | 109 | runner->setResultTransformation(mResultTransformation); |
110 | return qMakePair(KAsync::null<void>(), runner->emitter()); | 110 | return qMakePair(KAsync::null<void>(), runner->emitter()); |
111 | } | 111 | } |
diff --git a/common/facade.h b/common/facade.h index c10886f..2149acd 100644 --- a/common/facade.h +++ b/common/facade.h | |||
@@ -66,7 +66,7 @@ public: | |||
66 | KAsync::Job<void> move(const DomainType &domainObject, const QByteArray &newResource) Q_DECL_OVERRIDE; | 66 | KAsync::Job<void> move(const DomainType &domainObject, const QByteArray &newResource) Q_DECL_OVERRIDE; |
67 | KAsync::Job<void> copy(const DomainType &domainObject, const QByteArray &newResource) Q_DECL_OVERRIDE; | 67 | KAsync::Job<void> copy(const DomainType &domainObject, const QByteArray &newResource) Q_DECL_OVERRIDE; |
68 | KAsync::Job<void> remove(const DomainType &domainObject) Q_DECL_OVERRIDE; | 68 | KAsync::Job<void> remove(const DomainType &domainObject) Q_DECL_OVERRIDE; |
69 | virtual QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE; | 69 | virtual QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Sink::Query &query, const Log::Context &) Q_DECL_OVERRIDE; |
70 | 70 | ||
71 | protected: | 71 | protected: |
72 | std::function<void(Sink::ApplicationDomain::ApplicationDomainType &domainObject)> mResultTransformation; | 72 | std::function<void(Sink::ApplicationDomain::ApplicationDomainType &domainObject)> mResultTransformation; |
diff --git a/common/facadeinterface.h b/common/facadeinterface.h index 5d12360..26a8407 100644 --- a/common/facadeinterface.h +++ b/common/facadeinterface.h | |||
@@ -29,6 +29,9 @@ | |||
29 | 29 | ||
30 | namespace Sink { | 30 | namespace Sink { |
31 | class Query; | 31 | class Query; |
32 | namespace Log { | ||
33 | struct Context; | ||
34 | } | ||
32 | 35 | ||
33 | /** | 36 | /** |
34 | * Interface for the store facade. | 37 | * Interface for the store facade. |
@@ -86,7 +89,7 @@ public: | |||
86 | /** | 89 | /** |
87 | * Load entities from the store. | 90 | * Load entities from the store. |
88 | */ | 91 | */ |
89 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Query &query) = 0; | 92 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Query &query, const Log::Context &) = 0; |
90 | }; | 93 | }; |
91 | 94 | ||
92 | template <class DomainType> | 95 | template <class DomainType> |
@@ -119,7 +122,7 @@ public: | |||
119 | return KAsync::error<void>(-1, "Failed to create a facade"); | 122 | return KAsync::error<void>(-1, "Failed to create a facade"); |
120 | } | 123 | } |
121 | 124 | ||
122 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Query &query) | 125 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Query &query, const Log::Context &) |
123 | { | 126 | { |
124 | return qMakePair(KAsync::null<void>(), typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr()); | 127 | return qMakePair(KAsync::null<void>(), typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr()); |
125 | } | 128 | } |
diff --git a/common/log.h b/common/log.h index f47a3ae..9063ac8 100644 --- a/common/log.h +++ b/common/log.h | |||
@@ -6,6 +6,14 @@ | |||
6 | namespace Sink { | 6 | namespace Sink { |
7 | namespace Log { | 7 | namespace Log { |
8 | 8 | ||
9 | struct Context { | ||
10 | Context() = default; | ||
11 | QByteArray name; | ||
12 | Context subContext(const QByteArray &sub) const { | ||
13 | return Context{name + "." + sub}; | ||
14 | } | ||
15 | }; | ||
16 | |||
9 | enum DebugLevel | 17 | enum DebugLevel |
10 | { | 18 | { |
11 | Trace, | 19 | Trace, |
@@ -91,6 +99,11 @@ static const char *getComponentName() { return nullptr; } | |||
91 | #define SinkWarning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName()) | 99 | #define SinkWarning() Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName()) |
92 | #define SinkError() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName()) | 100 | #define SinkError() Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, s_sinkDebugArea, getComponentName()) |
93 | 101 | ||
102 | #define SinkTraceCtx(CTX) Sink::Log::debugStream(Sink::Log::DebugLevel::Trace, __LINE__, __FILE__, Q_FUNC_INFO, CTX.name, getComponentName()) | ||
103 | #define SinkLogCtx(CTX) Sink::Log::debugStream(Sink::Log::DebugLevel::Log, __LINE__, __FILE__, Q_FUNC_INFO, CTX.name, getComponentName()) | ||
104 | #define SinkWarningCtx(CTX) Sink::Log::debugStream(Sink::Log::DebugLevel::Warning, __LINE__, __FILE__, Q_FUNC_INFO, CTX.name, getComponentName()) | ||
105 | #define SinkErrorCtx(CTX) Sink::Log::debugStream(Sink::Log::DebugLevel::Error, __LINE__, __FILE__, Q_FUNC_INFO, CTX.name, getComponentName()) | ||
106 | |||
94 | #define SINK_DEBUG_AREA(AREA) static constexpr const char* s_sinkDebugArea{AREA}; | 107 | #define SINK_DEBUG_AREA(AREA) static constexpr const char* s_sinkDebugArea{AREA}; |
95 | #define SINK_DEBUG_COMPONENT(COMPONENT) const char* getComponentName() const { return COMPONENT; }; | 108 | #define SINK_DEBUG_COMPONENT(COMPONENT) const char* getComponentName() const { return COMPONENT; }; |
96 | #define SINK_DEBUG_COMPONENT_STATIC(COMPONENT) static const char* getComponentName() { return COMPONENT; }; | 109 | #define SINK_DEBUG_COMPONENT_STATIC(COMPONENT) static const char* getComponentName() { return COMPONENT; }; |
diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 0eb6df5..c9a8092 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp | |||
@@ -49,7 +49,7 @@ using namespace Sink::Storage; | |||
49 | class Pipeline::Private | 49 | class Pipeline::Private |
50 | { | 50 | { |
51 | public: | 51 | public: |
52 | Private(const ResourceContext &context) : resourceContext(context), entityStore(context), revisionChanged(false) | 52 | Private(const ResourceContext &context) : resourceContext(context), entityStore(context, {"pipeline"}), revisionChanged(false) |
53 | { | 53 | { |
54 | } | 54 | } |
55 | 55 | ||
diff --git a/common/queryrunner.cpp b/common/queryrunner.cpp index 377e3b9..ab4d60b 100644 --- a/common/queryrunner.cpp +++ b/common/queryrunner.cpp | |||
@@ -47,10 +47,8 @@ template <typename DomainType> | |||
47 | class QueryWorker : public QObject | 47 | class QueryWorker : public QObject |
48 | { | 48 | { |
49 | typedef std::function<bool(const typename DomainType::Ptr &domainObject, Sink::Operation operation, const QMap<QByteArray, QVariant> &aggregateValues)> ResultCallback; | 49 | typedef std::function<bool(const typename DomainType::Ptr &domainObject, Sink::Operation operation, const QMap<QByteArray, QVariant> &aggregateValues)> ResultCallback; |
50 | // SINK_DEBUG_COMPONENT(mResourceInstanceIdentifier, mId) | ||
51 | SINK_DEBUG_COMPONENT(mResourceContext.resourceInstanceIdentifier) | ||
52 | public: | 50 | public: |
53 | QueryWorker(const Sink::Query &query, const ResourceContext &context, const QByteArray &bufferType, const QueryRunnerBase::ResultTransformation &transformation); | 51 | QueryWorker(const Sink::Query &query, const ResourceContext &context, const QByteArray &bufferType, const QueryRunnerBase::ResultTransformation &transformation, const Sink::Log::Context &logCtx); |
54 | virtual ~QueryWorker(); | 52 | virtual ~QueryWorker(); |
55 | 53 | ||
56 | ReplayResult executeIncrementalQuery(const Sink::Query &query, Sink::ResultProviderInterface<typename DomainType::Ptr> &resultProvider); | 54 | ReplayResult executeIncrementalQuery(const Sink::Query &query, Sink::ResultProviderInterface<typename DomainType::Ptr> &resultProvider); |
@@ -61,14 +59,14 @@ private: | |||
61 | 59 | ||
62 | QueryRunnerBase::ResultTransformation mResultTransformation; | 60 | QueryRunnerBase::ResultTransformation mResultTransformation; |
63 | ResourceContext mResourceContext; | 61 | ResourceContext mResourceContext; |
64 | QByteArray mId; //Used for identification in debug output | 62 | Sink::Log::Context mLogCtx; |
65 | }; | 63 | }; |
66 | 64 | ||
67 | template <class DomainType> | 65 | template <class DomainType> |
68 | QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::ResourceContext &context, const QByteArray &bufferType) | 66 | QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::ResourceContext &context, const QByteArray &bufferType, const Sink::Log::Context &logCtx) |
69 | : QueryRunnerBase(), mResourceContext(context), mResourceAccess(mResourceContext.resourceAccess()), mResultProvider(new ResultProvider<typename DomainType::Ptr>), mBatchSize(query.limit()) | 67 | : QueryRunnerBase(), mResourceContext(context), mResourceAccess(mResourceContext.resourceAccess()), mResultProvider(new ResultProvider<typename DomainType::Ptr>), mBatchSize(query.limit()), mLogCtx(logCtx.subContext("queryrunner")) |
70 | { | 68 | { |
71 | SinkTrace() << "Starting query. Is live:" << query.liveQuery() << " Limit: " << query.limit(); | 69 | SinkTraceCtx(mLogCtx) << "Starting query. Is live:" << query.liveQuery() << " Limit: " << query.limit(); |
72 | if (query.limit() && query.sortProperty().isEmpty()) { | 70 | if (query.limit() && query.sortProperty().isEmpty()) { |
73 | SinkWarning() << "A limited query without sorting is typically a bad idea, because there is no telling what you're going to get."; | 71 | SinkWarning() << "A limited query without sorting is typically a bad idea, because there is no telling what you're going to get."; |
74 | } | 72 | } |
@@ -76,10 +74,10 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou | |||
76 | // We delegate loading of initial data to the result provider, so it can decide for itself what it needs to load. | 74 | // We delegate loading of initial data to the result provider, so it can decide for itself what it needs to load. |
77 | mResultProvider->setFetcher([=](const typename DomainType::Ptr &parent) { | 75 | mResultProvider->setFetcher([=](const typename DomainType::Ptr &parent) { |
78 | const QByteArray parentId = parent ? parent->identifier() : QByteArray(); | 76 | const QByteArray parentId = parent ? parent->identifier() : QByteArray(); |
79 | SinkTrace() << "Running fetcher. Offset: " << mOffset[parentId] << " Batchsize: " << mBatchSize; | 77 | SinkTraceCtx(mLogCtx) << "Running fetcher. Offset: " << mOffset[parentId] << " Batchsize: " << mBatchSize; |
80 | auto resultProvider = mResultProvider; | 78 | auto resultProvider = mResultProvider; |
81 | if (query.synchronousQuery()) { | 79 | if (query.synchronousQuery()) { |
82 | QueryWorker<DomainType> worker(query, mResourceContext, bufferType, mResultTransformation); | 80 | QueryWorker<DomainType> worker(query, mResourceContext, bufferType, mResultTransformation, mLogCtx); |
83 | const auto newRevisionAndReplayedEntities = worker.executeInitialQuery(query, parent, *resultProvider, mOffset[parentId], mBatchSize); | 81 | const auto newRevisionAndReplayedEntities = worker.executeInitialQuery(query, parent, *resultProvider, mOffset[parentId], mBatchSize); |
84 | mOffset[parentId] += newRevisionAndReplayedEntities.replayedEntities; | 82 | mOffset[parentId] += newRevisionAndReplayedEntities.replayedEntities; |
85 | resultProvider->setRevision(newRevisionAndReplayedEntities.newRevision); | 83 | resultProvider->setRevision(newRevisionAndReplayedEntities.newRevision); |
@@ -89,9 +87,10 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou | |||
89 | auto offset = mOffset[parentId]; | 87 | auto offset = mOffset[parentId]; |
90 | auto batchSize = mBatchSize; | 88 | auto batchSize = mBatchSize; |
91 | auto resourceContext = mResourceContext; | 89 | auto resourceContext = mResourceContext; |
90 | auto logCtx = mLogCtx; | ||
92 | //The lambda will be executed in a separate thread, so copy all arguments | 91 | //The lambda will be executed in a separate thread, so copy all arguments |
93 | async::run<ReplayResult>([resultTransformation, offset, batchSize, query, bufferType, resourceContext, resultProvider, parent]() { | 92 | async::run<ReplayResult>([resultTransformation, offset, batchSize, query, bufferType, resourceContext, resultProvider, parent, logCtx]() { |
94 | QueryWorker<DomainType> worker(query, resourceContext, bufferType, resultTransformation); | 93 | QueryWorker<DomainType> worker(query, resourceContext, bufferType, resultTransformation, logCtx); |
95 | const auto newRevisionAndReplayedEntities = worker.executeInitialQuery(query, parent, *resultProvider, offset, batchSize); | 94 | const auto newRevisionAndReplayedEntities = worker.executeInitialQuery(query, parent, *resultProvider, offset, batchSize); |
96 | return newRevisionAndReplayedEntities; | 95 | return newRevisionAndReplayedEntities; |
97 | }) | 96 | }) |
@@ -119,8 +118,9 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou | |||
119 | setQuery([=]() -> KAsync::Job<void> { | 118 | setQuery([=]() -> KAsync::Job<void> { |
120 | auto resultProvider = mResultProvider; | 119 | auto resultProvider = mResultProvider; |
121 | auto resourceContext = mResourceContext; | 120 | auto resourceContext = mResourceContext; |
121 | auto logCtx = mLogCtx; | ||
122 | return async::run<ReplayResult>([=]() { | 122 | return async::run<ReplayResult>([=]() { |
123 | QueryWorker<DomainType> worker(query, resourceContext, bufferType, mResultTransformation); | 123 | QueryWorker<DomainType> worker(query, resourceContext, bufferType, mResultTransformation, logCtx); |
124 | const auto newRevisionAndReplayedEntities = worker.executeIncrementalQuery(query, *resultProvider); | 124 | const auto newRevisionAndReplayedEntities = worker.executeIncrementalQuery(query, *resultProvider); |
125 | return newRevisionAndReplayedEntities; | 125 | return newRevisionAndReplayedEntities; |
126 | }) | 126 | }) |
@@ -147,7 +147,7 @@ QueryRunner<DomainType>::QueryRunner(const Sink::Query &query, const Sink::Resou | |||
147 | template <class DomainType> | 147 | template <class DomainType> |
148 | QueryRunner<DomainType>::~QueryRunner() | 148 | QueryRunner<DomainType>::~QueryRunner() |
149 | { | 149 | { |
150 | SinkTrace() << "Stopped query"; | 150 | SinkTraceCtx(mLogCtx) << "Stopped query"; |
151 | } | 151 | } |
152 | 152 | ||
153 | template <class DomainType> | 153 | template <class DomainType> |
@@ -164,16 +164,16 @@ typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr QueryRunner<DomainTy | |||
164 | 164 | ||
165 | template <class DomainType> | 165 | template <class DomainType> |
166 | QueryWorker<DomainType>::QueryWorker(const Sink::Query &query, const Sink::ResourceContext &resourceContext, | 166 | QueryWorker<DomainType>::QueryWorker(const Sink::Query &query, const Sink::ResourceContext &resourceContext, |
167 | const QByteArray &bufferType, const QueryRunnerBase::ResultTransformation &transformation) | 167 | const QByteArray &bufferType, const QueryRunnerBase::ResultTransformation &transformation, const Sink::Log::Context &logCtx) |
168 | : QObject(), mResultTransformation(transformation), mResourceContext(resourceContext), mId(QUuid::createUuid().toByteArray()) | 168 | : QObject(), mResultTransformation(transformation), mResourceContext(resourceContext), mLogCtx(logCtx.subContext("worker")) |
169 | { | 169 | { |
170 | SinkTrace() << "Starting query worker"; | 170 | SinkTraceCtx(mLogCtx) << "Starting query worker"; |
171 | } | 171 | } |
172 | 172 | ||
173 | template <class DomainType> | 173 | template <class DomainType> |
174 | QueryWorker<DomainType>::~QueryWorker() | 174 | QueryWorker<DomainType>::~QueryWorker() |
175 | { | 175 | { |
176 | SinkTrace() << "Stopped query worker"; | 176 | SinkTraceCtx(mLogCtx) << "Stopped query worker"; |
177 | } | 177 | } |
178 | 178 | ||
179 | template <class DomainType> | 179 | template <class DomainType> |
@@ -209,15 +209,15 @@ ReplayResult QueryWorker<DomainType>::executeIncrementalQuery(const Sink::Query | |||
209 | time.start(); | 209 | time.start(); |
210 | 210 | ||
211 | const qint64 baseRevision = resultProvider.revision() + 1; | 211 | const qint64 baseRevision = resultProvider.revision() + 1; |
212 | auto entityStore = EntityStore{mResourceContext}; | 212 | auto entityStore = EntityStore{mResourceContext, mLogCtx}; |
213 | auto preparedQuery = DataStoreQuery{query, ApplicationDomain::getTypeName<DomainType>(), entityStore}; | 213 | auto preparedQuery = DataStoreQuery{query, ApplicationDomain::getTypeName<DomainType>(), entityStore}; |
214 | auto resultSet = preparedQuery.update(baseRevision); | 214 | auto resultSet = preparedQuery.update(baseRevision); |
215 | SinkTrace() << "Filtered set retrieved. " << Log::TraceTime(time.elapsed()); | 215 | SinkTraceCtx(mLogCtx) << "Filtered set retrieved. " << Log::TraceTime(time.elapsed()); |
216 | auto replayResult = resultSet.replaySet(0, 0, [this, query, &resultProvider](const ResultSet::Result &result) { | 216 | auto replayResult = resultSet.replaySet(0, 0, [this, query, &resultProvider](const ResultSet::Result &result) { |
217 | resultProviderCallback(query, resultProvider, result); | 217 | resultProviderCallback(query, resultProvider, result); |
218 | }); | 218 | }); |
219 | 219 | ||
220 | SinkTrace() << "Incremental query took: " << Log::TraceTime(time.elapsed()); | 220 | SinkTraceCtx(mLogCtx) << "Incremental query took: " << Log::TraceTime(time.elapsed()); |
221 | return {entityStore.maxRevision(), replayResult.replayedEntities, replayResult.replayedAll}; | 221 | return {entityStore.maxRevision(), replayResult.replayedEntities, replayResult.replayedAll}; |
222 | } | 222 | } |
223 | 223 | ||
@@ -231,24 +231,24 @@ ReplayResult QueryWorker<DomainType>::executeInitialQuery( | |||
231 | auto modifiedQuery = query; | 231 | auto modifiedQuery = query; |
232 | if (!query.parentProperty().isEmpty()) { | 232 | if (!query.parentProperty().isEmpty()) { |
233 | if (parent) { | 233 | if (parent) { |
234 | SinkTrace() << "Running initial query for parent:" << parent->identifier(); | 234 | SinkTraceCtx(mLogCtx) << "Running initial query for parent:" << parent->identifier(); |
235 | modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant::fromValue(Sink::ApplicationDomain::Reference{parent->identifier()}))); | 235 | modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant::fromValue(Sink::ApplicationDomain::Reference{parent->identifier()}))); |
236 | } else { | 236 | } else { |
237 | SinkTrace() << "Running initial query for toplevel"; | 237 | SinkTraceCtx(mLogCtx) << "Running initial query for toplevel"; |
238 | modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant{})); | 238 | modifiedQuery.filter(query.parentProperty(), Query::Comparator(QVariant{})); |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | auto entityStore = EntityStore{mResourceContext}; | 242 | auto entityStore = EntityStore{mResourceContext, mLogCtx}; |
243 | auto preparedQuery = DataStoreQuery{modifiedQuery, ApplicationDomain::getTypeName<DomainType>(), entityStore}; | 243 | auto preparedQuery = DataStoreQuery{modifiedQuery, ApplicationDomain::getTypeName<DomainType>(), entityStore}; |
244 | auto resultSet = preparedQuery.execute(); | 244 | auto resultSet = preparedQuery.execute(); |
245 | 245 | ||
246 | SinkTrace() << "Filtered set retrieved. " << Log::TraceTime(time.elapsed()); | 246 | SinkTraceCtx(mLogCtx) << "Filtered set retrieved. " << Log::TraceTime(time.elapsed()); |
247 | auto replayResult = resultSet.replaySet(offset, batchsize, [this, query, &resultProvider](const ResultSet::Result &result) { | 247 | auto replayResult = resultSet.replaySet(offset, batchsize, [this, query, &resultProvider](const ResultSet::Result &result) { |
248 | resultProviderCallback(query, resultProvider, result); | 248 | resultProviderCallback(query, resultProvider, result); |
249 | }); | 249 | }); |
250 | 250 | ||
251 | SinkTrace() << "Initial query took: " << Log::TraceTime(time.elapsed()); | 251 | SinkTraceCtx(mLogCtx) << "Initial query took: " << Log::TraceTime(time.elapsed()); |
252 | return {entityStore.maxRevision(), replayResult.replayedEntities, replayResult.replayedAll}; | 252 | return {entityStore.maxRevision(), replayResult.replayedEntities, replayResult.replayedAll}; |
253 | } | 253 | } |
254 | 254 | ||
diff --git a/common/queryrunner.h b/common/queryrunner.h index 7e3d688..66dc68f 100644 --- a/common/queryrunner.h +++ b/common/queryrunner.h | |||
@@ -53,7 +53,6 @@ protected slots: | |||
53 | */ | 53 | */ |
54 | void revisionChanged(qint64 newRevision) | 54 | void revisionChanged(qint64 newRevision) |
55 | { | 55 | { |
56 | SinkTrace() << "New revision: " << newRevision; | ||
57 | run().exec(); | 56 | run().exec(); |
58 | } | 57 | } |
59 | 58 | ||
@@ -82,7 +81,7 @@ template <typename DomainType> | |||
82 | class QueryRunner : public QueryRunnerBase | 81 | class QueryRunner : public QueryRunnerBase |
83 | { | 82 | { |
84 | public: | 83 | public: |
85 | QueryRunner(const Sink::Query &query, const Sink::ResourceContext &context, const QByteArray &bufferType); | 84 | QueryRunner(const Sink::Query &query, const Sink::ResourceContext &context, const QByteArray &bufferType, const Sink::Log::Context &logCtx); |
86 | virtual ~QueryRunner(); | 85 | virtual ~QueryRunner(); |
87 | 86 | ||
88 | /** | 87 | /** |
@@ -95,11 +94,11 @@ public: | |||
95 | 94 | ||
96 | private: | 95 | private: |
97 | Sink::ResourceContext mResourceContext; | 96 | Sink::ResourceContext mResourceContext; |
98 | SINK_DEBUG_COMPONENT(mResourceContext.resourceInstanceIdentifier) | ||
99 | QSharedPointer<Sink::ResourceAccessInterface> mResourceAccess; | 97 | QSharedPointer<Sink::ResourceAccessInterface> mResourceAccess; |
100 | QSharedPointer<Sink::ResultProvider<typename DomainType::Ptr>> mResultProvider; | 98 | QSharedPointer<Sink::ResultProvider<typename DomainType::Ptr>> mResultProvider; |
101 | ResultTransformation mResultTransformation; | 99 | ResultTransformation mResultTransformation; |
102 | QHash<QByteArray, qint64> mOffset; | 100 | QHash<QByteArray, qint64> mOffset; |
103 | int mBatchSize; | 101 | int mBatchSize; |
104 | QObject guard; | 102 | QObject guard; |
103 | Sink::Log::Context mLogCtx; | ||
105 | }; | 104 | }; |
diff --git a/common/resourceaccess.h b/common/resourceaccess.h index c1b4253..e0e9545 100644 --- a/common/resourceaccess.h +++ b/common/resourceaccess.h | |||
@@ -149,7 +149,6 @@ private: | |||
149 | 149 | ||
150 | class Private; | 150 | class Private; |
151 | Private *const d; | 151 | Private *const d; |
152 | // SINK_DEBUG_COMPONENT(d->resourceInstanceIdentifier) | ||
153 | }; | 152 | }; |
154 | 153 | ||
155 | /** | 154 | /** |
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 861d37a..1c6b0c8 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -85,8 +85,8 @@ static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, co | |||
85 | } | 85 | } |
86 | 86 | ||
87 | template<typename DomainType> | 87 | template<typename DomainType> |
88 | LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier) | 88 | LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier, const Sink::Log::Context &ctx) |
89 | : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier, typeName), mGuard(new QObject) | 89 | : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier, typeName), mGuard(new QObject), mLogCtx(ctx.subContext("config")) |
90 | { | 90 | { |
91 | QObject *guard = new QObject; | 91 | QObject *guard = new QObject; |
92 | mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer<DomainType> &) { | 92 | mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer<DomainType> &) { |
@@ -95,7 +95,7 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
95 | const auto type = entries.value(res); | 95 | const auto type = entries.value(res); |
96 | 96 | ||
97 | if (query.hasFilter(ApplicationDomain::SinkResource::ResourceType::name) && query.getFilter(ApplicationDomain::SinkResource::ResourceType::name).value.toByteArray() != type) { | 97 | if (query.hasFilter(ApplicationDomain::SinkResource::ResourceType::name) && query.getFilter(ApplicationDomain::SinkResource::ResourceType::name).value.toByteArray() != type) { |
98 | SinkTrace() << "Skipping due to type."; | 98 | SinkTraceCtx(mLogCtx) << "Skipping due to type."; |
99 | continue; | 99 | continue; |
100 | } | 100 | } |
101 | if (!query.ids().isEmpty() && !query.ids().contains(res)) { | 101 | if (!query.ids().isEmpty() && !query.ids().contains(res)) { |
@@ -103,10 +103,10 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
103 | } | 103 | } |
104 | auto entity = readFromConfig<DomainType>(mConfigStore, res, type); | 104 | auto entity = readFromConfig<DomainType>(mConfigStore, res, type); |
105 | if (!matchesFilter(query.getBaseFilters(), *entity)){ | 105 | if (!matchesFilter(query.getBaseFilters(), *entity)){ |
106 | SinkTrace() << "Skipping due to filter." << res; | 106 | SinkTraceCtx(mLogCtx) << "Skipping due to filter." << res; |
107 | continue; | 107 | continue; |
108 | } | 108 | } |
109 | SinkTrace() << "Found match " << res; | 109 | SinkTraceCtx(mLogCtx) << "Found match " << res; |
110 | updateStatus(*entity); | 110 | updateStatus(*entity); |
111 | mResultProvider->add(entity); | 111 | mResultProvider->add(entity); |
112 | } | 112 | } |
@@ -118,7 +118,7 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
118 | { | 118 | { |
119 | auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { | 119 | auto ret = QObject::connect(&configNotifier, &ConfigNotifier::added, guard, [this](const ApplicationDomain::ApplicationDomainType::Ptr &entry) { |
120 | auto entity = entry.staticCast<DomainType>(); | 120 | auto entity = entry.staticCast<DomainType>(); |
121 | SinkTrace() << "A new resource has been added: " << entity->identifier(); | 121 | SinkTraceCtx(mLogCtx) << "A new resource has been added: " << entity->identifier(); |
122 | updateStatus(*entity); | 122 | updateStatus(*entity); |
123 | mResultProvider->add(entity); | 123 | mResultProvider->add(entity); |
124 | }); | 124 | }); |
@@ -165,7 +165,7 @@ void LocalStorageQueryRunner<DomainType>::setStatusUpdater(const std::function<v | |||
165 | template<typename DomainType> | 165 | template<typename DomainType> |
166 | void LocalStorageQueryRunner<DomainType>::statusChanged(const QByteArray &identifier) | 166 | void LocalStorageQueryRunner<DomainType>::statusChanged(const QByteArray &identifier) |
167 | { | 167 | { |
168 | SinkTrace() << "Status changed " << identifier; | 168 | SinkTraceCtx(mLogCtx) << "Status changed " << identifier; |
169 | auto entity = readFromConfig<DomainType>(mConfigStore, identifier, ApplicationDomain::getTypeName<DomainType>()); | 169 | auto entity = readFromConfig<DomainType>(mConfigStore, identifier, ApplicationDomain::getTypeName<DomainType>()); |
170 | updateStatus(*entity); | 170 | updateStatus(*entity); |
171 | mResultProvider->modify(entity); | 171 | mResultProvider->modify(entity); |
@@ -274,9 +274,10 @@ KAsync::Job<void> LocalStorageFacade<DomainType>::remove(const DomainType &domai | |||
274 | } | 274 | } |
275 | 275 | ||
276 | template <typename DomainType> | 276 | template <typename DomainType> |
277 | QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> LocalStorageFacade<DomainType>::load(const Query &query) | 277 | QPair<KAsync::Job<void>, typename ResultEmitter<typename DomainType::Ptr>::Ptr> LocalStorageFacade<DomainType>::load(const Query &query, const Sink::Log::Context &parentCtx) |
278 | { | 278 | { |
279 | auto runner = new LocalStorageQueryRunner<DomainType>(query, mIdentifier, mTypeName, sConfigNotifier); | 279 | auto ctx = parentCtx.subContext(ApplicationDomain::getTypeName<DomainType>()); |
280 | auto runner = new LocalStorageQueryRunner<DomainType>(query, mIdentifier, mTypeName, sConfigNotifier, ctx); | ||
280 | return qMakePair(KAsync::null<void>(), runner->emitter()); | 281 | return qMakePair(KAsync::null<void>(), runner->emitter()); |
281 | } | 282 | } |
282 | 283 | ||
@@ -294,15 +295,16 @@ KAsync::Job<void> ResourceFacade::remove(const Sink::ApplicationDomain::SinkReso | |||
294 | return Sink::Store::removeDataFromDisk(identifier).then(LocalStorageFacade<Sink::ApplicationDomain::SinkResource>::remove(resource)); | 295 | return Sink::Store::removeDataFromDisk(identifier).then(LocalStorageFacade<Sink::ApplicationDomain::SinkResource>::remove(resource)); |
295 | } | 296 | } |
296 | 297 | ||
297 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkResource::Ptr>::Ptr> ResourceFacade::load(const Sink::Query &query) | 298 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkResource::Ptr>::Ptr> ResourceFacade::load(const Sink::Query &query, const Sink::Log::Context &parentCtx) |
298 | { | 299 | { |
299 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkResource>(query, mIdentifier, mTypeName, sConfigNotifier); | 300 | auto ctx = parentCtx.subContext("resource"); |
301 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkResource>(query, mIdentifier, mTypeName, sConfigNotifier, ctx); | ||
300 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); | 302 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); |
301 | runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkResource &resource) { | 303 | runner->setStatusUpdater([runner, monitoredResources, ctx](ApplicationDomain::SinkResource &resource) { |
302 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); | 304 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); |
303 | if (!monitoredResources->contains(resource.identifier())) { | 305 | if (!monitoredResources->contains(resource.identifier())) { |
304 | auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess](const Notification ¬ification) { | 306 | auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess, ctx](const Notification ¬ification) { |
305 | SinkTrace() << "Received notification in facade: " << notification.type; | 307 | SinkTraceCtx(ctx) << "Received notification in facade: " << notification.type; |
306 | if (notification.type == Notification::Status) { | 308 | if (notification.type == Notification::Status) { |
307 | runner->statusChanged(resource.identifier()); | 309 | runner->statusChanged(resource.identifier()); |
308 | } | 310 | } |
@@ -324,22 +326,23 @@ AccountFacade::~AccountFacade() | |||
324 | { | 326 | { |
325 | } | 327 | } |
326 | 328 | ||
327 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkAccount::Ptr>::Ptr> AccountFacade::load(const Sink::Query &query) | 329 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain::SinkAccount::Ptr>::Ptr> AccountFacade::load(const Sink::Query &query, const Sink::Log::Context &parentCtx) |
328 | { | 330 | { |
329 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkAccount>(query, mIdentifier, mTypeName, sConfigNotifier); | 331 | auto ctx = parentCtx.subContext("accounts"); |
332 | auto runner = new LocalStorageQueryRunner<ApplicationDomain::SinkAccount>(query, mIdentifier, mTypeName, sConfigNotifier, ctx); | ||
330 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); | 333 | auto monitoredResources = QSharedPointer<QSet<QByteArray>>::create(); |
331 | runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkAccount &account) { | 334 | runner->setStatusUpdater([runner, monitoredResources, ctx](ApplicationDomain::SinkAccount &account) { |
332 | Query query; | 335 | Query query; |
333 | query.filter<ApplicationDomain::SinkResource::Account>(account.identifier()); | 336 | query.filter<ApplicationDomain::SinkResource::Account>(account.identifier()); |
334 | const auto resources = Store::read<ApplicationDomain::SinkResource>(query); | 337 | const auto resources = Store::read<ApplicationDomain::SinkResource>(query); |
335 | SinkTrace() << "Found resource belonging to the account " << account.identifier() << " : " << resources; | 338 | SinkTraceCtx(ctx) << "Found resource belonging to the account " << account.identifier() << " : " << resources; |
336 | auto accountIdentifier = account.identifier(); | 339 | auto accountIdentifier = account.identifier(); |
337 | ApplicationDomain::Status status = ApplicationDomain::ConnectedStatus; | 340 | ApplicationDomain::Status status = ApplicationDomain::ConnectedStatus; |
338 | for (const auto &resource : resources) { | 341 | for (const auto &resource : resources) { |
339 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); | 342 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); |
340 | if (!monitoredResources->contains(resource.identifier())) { | 343 | if (!monitoredResources->contains(resource.identifier())) { |
341 | auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess, accountIdentifier](const Notification ¬ification) { | 344 | auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess, accountIdentifier, ctx](const Notification ¬ification) { |
342 | SinkTrace() << "Received notification in facade: " << notification.type; | 345 | SinkTraceCtx(ctx) << "Received notification in facade: " << notification.type; |
343 | if (notification.type == Notification::Status) { | 346 | if (notification.type == Notification::Status) { |
344 | runner->statusChanged(accountIdentifier); | 347 | runner->statusChanged(accountIdentifier); |
345 | } | 348 | } |
diff --git a/common/resourcefacade.h b/common/resourcefacade.h index 4575e72..509b37a 100644 --- a/common/resourcefacade.h +++ b/common/resourcefacade.h | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "common/resultprovider.h" | 25 | #include "common/resultprovider.h" |
26 | #include "common/domain/applicationdomaintype.h" | 26 | #include "common/domain/applicationdomaintype.h" |
27 | #include "common/configstore.h" | 27 | #include "common/configstore.h" |
28 | #include "common/log.h" | ||
28 | 29 | ||
29 | namespace Sink { | 30 | namespace Sink { |
30 | class Query; | 31 | class Query; |
@@ -59,7 +60,7 @@ template <typename DomainType> | |||
59 | class LocalStorageQueryRunner | 60 | class LocalStorageQueryRunner |
60 | { | 61 | { |
61 | public: | 62 | public: |
62 | LocalStorageQueryRunner(const Sink::Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier); | 63 | LocalStorageQueryRunner(const Sink::Query &query, const QByteArray &identifier, const QByteArray &typeName, ConfigNotifier &configNotifier, const Sink::Log::Context &); |
63 | typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr emitter(); | 64 | typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr emitter(); |
64 | void setStatusUpdater(const std::function<void(DomainType &)> &); | 65 | void setStatusUpdater(const std::function<void(DomainType &)> &); |
65 | void statusChanged(const QByteArray &identifier); | 66 | void statusChanged(const QByteArray &identifier); |
@@ -71,6 +72,7 @@ private: | |||
71 | QSharedPointer<Sink::ResultProvider<typename DomainType::Ptr>> mResultProvider; | 72 | QSharedPointer<Sink::ResultProvider<typename DomainType::Ptr>> mResultProvider; |
72 | ConfigStore mConfigStore; | 73 | ConfigStore mConfigStore; |
73 | std::unique_ptr<QObject> mGuard; | 74 | std::unique_ptr<QObject> mGuard; |
75 | Sink::Log::Context mLogCtx; | ||
74 | }; | 76 | }; |
75 | 77 | ||
76 | template <typename DomainType> | 78 | template <typename DomainType> |
@@ -84,7 +86,7 @@ public: | |||
84 | virtual KAsync::Job<void> move(const DomainType &resource, const QByteArray &) Q_DECL_OVERRIDE; | 86 | virtual KAsync::Job<void> move(const DomainType &resource, const QByteArray &) Q_DECL_OVERRIDE; |
85 | virtual KAsync::Job<void> copy(const DomainType &resource, const QByteArray &) Q_DECL_OVERRIDE; | 87 | virtual KAsync::Job<void> copy(const DomainType &resource, const QByteArray &) Q_DECL_OVERRIDE; |
86 | virtual KAsync::Job<void> remove(const DomainType &resource) Q_DECL_OVERRIDE; | 88 | virtual KAsync::Job<void> remove(const DomainType &resource) Q_DECL_OVERRIDE; |
87 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE; | 89 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr> load(const Sink::Query &query, const Sink::Log::Context &) Q_DECL_OVERRIDE; |
88 | 90 | ||
89 | protected: | 91 | protected: |
90 | QByteArray mIdentifier; | 92 | QByteArray mIdentifier; |
@@ -98,7 +100,7 @@ public: | |||
98 | ResourceFacade(); | 100 | ResourceFacade(); |
99 | virtual ~ResourceFacade(); | 101 | virtual ~ResourceFacade(); |
100 | virtual KAsync::Job<void> remove(const Sink::ApplicationDomain::SinkResource &resource) Q_DECL_OVERRIDE; | 102 | virtual KAsync::Job<void> remove(const Sink::ApplicationDomain::SinkResource &resource) Q_DECL_OVERRIDE; |
101 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename Sink::ApplicationDomain::SinkResource::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE; | 103 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename Sink::ApplicationDomain::SinkResource::Ptr>::Ptr> load(const Sink::Query &query, const Sink::Log::Context &) Q_DECL_OVERRIDE; |
102 | }; | 104 | }; |
103 | 105 | ||
104 | class AccountFacade : public LocalStorageFacade<Sink::ApplicationDomain::SinkAccount> | 106 | class AccountFacade : public LocalStorageFacade<Sink::ApplicationDomain::SinkAccount> |
@@ -106,7 +108,7 @@ class AccountFacade : public LocalStorageFacade<Sink::ApplicationDomain::SinkAcc | |||
106 | public: | 108 | public: |
107 | AccountFacade(); | 109 | AccountFacade(); |
108 | virtual ~AccountFacade(); | 110 | virtual ~AccountFacade(); |
109 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename Sink::ApplicationDomain::SinkAccount::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE; | 111 | virtual QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename Sink::ApplicationDomain::SinkAccount::Ptr>::Ptr> load(const Sink::Query &query, const Sink::Log::Context &) Q_DECL_OVERRIDE; |
110 | }; | 112 | }; |
111 | 113 | ||
112 | class IdentityFacade : public LocalStorageFacade<Sink::ApplicationDomain::Identity> | 114 | class IdentityFacade : public LocalStorageFacade<Sink::ApplicationDomain::Identity> |
diff --git a/common/storage/entitystore.cpp b/common/storage/entitystore.cpp index 6d48c10..6fc82de 100644 --- a/common/storage/entitystore.cpp +++ b/common/storage/entitystore.cpp | |||
@@ -41,11 +41,12 @@ SINK_DEBUG_AREA("entitystore"); | |||
41 | 41 | ||
42 | class EntityStore::Private { | 42 | class EntityStore::Private { |
43 | public: | 43 | public: |
44 | Private(const ResourceContext &context) : resourceContext(context) {} | 44 | Private(const ResourceContext &context, const Sink::Log::Context &ctx) : resourceContext(context), logCtx(ctx.subContext("entitystore")) {} |
45 | 45 | ||
46 | ResourceContext resourceContext; | 46 | ResourceContext resourceContext; |
47 | DataStore::Transaction transaction; | 47 | DataStore::Transaction transaction; |
48 | QHash<QByteArray, QSharedPointer<TypeIndex> > indexByType; | 48 | QHash<QByteArray, QSharedPointer<TypeIndex> > indexByType; |
49 | Sink::Log::Context logCtx; | ||
49 | 50 | ||
50 | bool exists() | 51 | bool exists() |
51 | { | 52 | { |
@@ -76,7 +77,7 @@ public: | |||
76 | if (indexByType.contains(type)) { | 77 | if (indexByType.contains(type)) { |
77 | return *indexByType.value(type); | 78 | return *indexByType.value(type); |
78 | } | 79 | } |
79 | auto index = QSharedPointer<TypeIndex>::create(type); | 80 | auto index = QSharedPointer<TypeIndex>::create(type, logCtx); |
80 | TypeHelper<ConfigureHelper>{type}.template operator()<void>(*index); | 81 | TypeHelper<ConfigureHelper>{type}.template operator()<void>(*index); |
81 | indexByType.insert(type, index); | 82 | indexByType.insert(type, index); |
82 | return *index; | 83 | return *index; |
@@ -103,15 +104,15 @@ public: | |||
103 | 104 | ||
104 | }; | 105 | }; |
105 | 106 | ||
106 | EntityStore::EntityStore(const ResourceContext &context) | 107 | EntityStore::EntityStore(const ResourceContext &context, const Log::Context &ctx) |
107 | : d(new EntityStore::Private{context}) | 108 | : d(new EntityStore::Private{context, ctx}) |
108 | { | 109 | { |
109 | 110 | ||
110 | } | 111 | } |
111 | 112 | ||
112 | void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) | 113 | void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMode) |
113 | { | 114 | { |
114 | SinkTrace() << "Starting transaction"; | 115 | SinkTraceCtx(d->logCtx) << "Starting transaction"; |
115 | Sink::Storage::DataStore store(Sink::storageLocation(), d->resourceContext.instanceId(), accessMode); | 116 | Sink::Storage::DataStore store(Sink::storageLocation(), d->resourceContext.instanceId(), accessMode); |
116 | d->transaction = store.createTransaction(accessMode); | 117 | d->transaction = store.createTransaction(accessMode); |
117 | Q_ASSERT(d->transaction.validateNamedDatabases()); | 118 | Q_ASSERT(d->transaction.validateNamedDatabases()); |
@@ -119,14 +120,14 @@ void EntityStore::startTransaction(Sink::Storage::DataStore::AccessMode accessMo | |||
119 | 120 | ||
120 | void EntityStore::commitTransaction() | 121 | void EntityStore::commitTransaction() |
121 | { | 122 | { |
122 | SinkTrace() << "Committing transaction"; | 123 | SinkTraceCtx(d->logCtx) << "Committing transaction"; |
123 | d->transaction.commit(); | 124 | d->transaction.commit(); |
124 | d->transaction = Storage::DataStore::Transaction(); | 125 | d->transaction = Storage::DataStore::Transaction(); |
125 | } | 126 | } |
126 | 127 | ||
127 | void EntityStore::abortTransaction() | 128 | void EntityStore::abortTransaction() |
128 | { | 129 | { |
129 | SinkTrace() << "Aborting transaction"; | 130 | SinkTraceCtx(d->logCtx) << "Aborting transaction"; |
130 | d->transaction.abort(); | 131 | d->transaction.abort(); |
131 | d->transaction = Storage::DataStore::Transaction(); | 132 | d->transaction = Storage::DataStore::Transaction(); |
132 | } | 133 | } |
@@ -172,7 +173,7 @@ bool EntityStore::add(const QByteArray &type, const ApplicationDomain::Applicati | |||
172 | auto entity = *ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<ApplicationDomain::ApplicationDomainType>(entity_, entity_.availableProperties()); | 173 | auto entity = *ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<ApplicationDomain::ApplicationDomainType>(entity_, entity_.availableProperties()); |
173 | entity.setChangedProperties(entity.availableProperties().toSet()); | 174 | entity.setChangedProperties(entity.availableProperties().toSet()); |
174 | 175 | ||
175 | SinkTrace() << "New entity " << entity; | 176 | SinkTraceCtx(d->logCtx) << "New entity " << entity; |
176 | 177 | ||
177 | preprocess(entity); | 178 | preprocess(entity); |
178 | d->typeIndex(type).add(entity.identifier(), entity, d->transaction); | 179 | d->typeIndex(type).add(entity.identifier(), entity, d->transaction); |
@@ -199,7 +200,7 @@ bool EntityStore::add(const QByteArray &type, const ApplicationDomain::Applicati | |||
199 | [&](const DataStore::Error &error) { SinkWarning() << "Failed to write entity" << entity.identifier() << newRevision; }); | 200 | [&](const DataStore::Error &error) { SinkWarning() << "Failed to write entity" << entity.identifier() << newRevision; }); |
200 | DataStore::setMaxRevision(d->transaction, newRevision); | 201 | DataStore::setMaxRevision(d->transaction, newRevision); |
201 | DataStore::recordRevision(d->transaction, newRevision, entity.identifier(), type); | 202 | DataStore::recordRevision(d->transaction, newRevision, entity.identifier(), type); |
202 | SinkTrace() << "Wrote entity: " << entity.identifier() << type << newRevision; | 203 | SinkTraceCtx(d->logCtx) << "Wrote entity: " << entity.identifier() << type << newRevision; |
203 | return true; | 204 | return true; |
204 | } | 205 | } |
205 | 206 | ||
@@ -214,6 +215,8 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic | |||
214 | 215 | ||
215 | auto newEntity = *ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<ApplicationDomain::ApplicationDomainType>(current, current.availableProperties()); | 216 | auto newEntity = *ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<ApplicationDomain::ApplicationDomainType>(current, current.availableProperties()); |
216 | 217 | ||
218 | SinkTraceCtx(d->logCtx) << "Modified entity: " << newEntity; | ||
219 | |||
217 | // Apply diff | 220 | // Apply diff |
218 | //SinkTrace() << "Applying changed properties: " << changeset; | 221 | //SinkTrace() << "Applying changed properties: " << changeset; |
219 | for (const auto &property : changeset) { | 222 | for (const auto &property : changeset) { |
@@ -251,8 +254,7 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic | |||
251 | auto metadataBuffer = metadataBuilder.Finish(); | 254 | auto metadataBuffer = metadataBuilder.Finish(); |
252 | FinishMetadataBuffer(metadataFbb, metadataBuffer); | 255 | FinishMetadataBuffer(metadataFbb, metadataBuffer); |
253 | } | 256 | } |
254 | SinkTrace() << "Modified entity: " << newEntity; | 257 | SinkTraceCtx(d->logCtx) << "Changed properties: " << changeset + newEntity.changedProperties(); |
255 | SinkTrace() << "Changed properties: " << changeset + newEntity.changedProperties(); | ||
256 | 258 | ||
257 | newEntity.setChangedProperties(newEntity.availableProperties().toSet()); | 259 | newEntity.setChangedProperties(newEntity.availableProperties().toSet()); |
258 | 260 | ||
@@ -264,7 +266,7 @@ bool EntityStore::modify(const QByteArray &type, const ApplicationDomain::Applic | |||
264 | [&](const DataStore::Error &error) { SinkWarning() << "Failed to write entity" << newEntity.identifier() << newRevision; }); | 266 | [&](const DataStore::Error &error) { SinkWarning() << "Failed to write entity" << newEntity.identifier() << newRevision; }); |
265 | DataStore::setMaxRevision(d->transaction, newRevision); | 267 | DataStore::setMaxRevision(d->transaction, newRevision); |
266 | DataStore::recordRevision(d->transaction, newRevision, newEntity.identifier(), type); | 268 | DataStore::recordRevision(d->transaction, newRevision, newEntity.identifier(), type); |
267 | SinkTrace() << "Wrote modified entity: " << newEntity.identifier() << type << newRevision; | 269 | SinkTraceCtx(d->logCtx) << "Wrote modified entity: " << newEntity.identifier() << type << newRevision; |
268 | return true; | 270 | return true; |
269 | } | 271 | } |
270 | 272 | ||
@@ -300,7 +302,7 @@ bool EntityStore::remove(const QByteArray &type, const QByteArray &uid, bool rep | |||
300 | preprocess(current); | 302 | preprocess(current); |
301 | d->typeIndex(type).remove(current.identifier(), current, d->transaction); | 303 | d->typeIndex(type).remove(current.identifier(), current, d->transaction); |
302 | 304 | ||
303 | SinkTrace() << "Removed entity " << current; | 305 | SinkTraceCtx(d->logCtx) << "Removed entity " << current; |
304 | 306 | ||
305 | const qint64 newRevision = DataStore::maxRevision(d->transaction) + 1; | 307 | const qint64 newRevision = DataStore::maxRevision(d->transaction) + 1; |
306 | 308 | ||
@@ -328,7 +330,7 @@ void EntityStore::cleanupRevision(qint64 revision) | |||
328 | { | 330 | { |
329 | const auto uid = DataStore::getUidFromRevision(d->transaction, revision); | 331 | const auto uid = DataStore::getUidFromRevision(d->transaction, revision); |
330 | const auto bufferType = DataStore::getTypeFromRevision(d->transaction, revision); | 332 | const auto bufferType = DataStore::getTypeFromRevision(d->transaction, revision); |
331 | SinkTrace() << "Cleaning up revision " << revision << uid << bufferType; | 333 | SinkTraceCtx(d->logCtx) << "Cleaning up revision " << revision << uid << bufferType; |
332 | DataStore::mainDatabase(d->transaction, bufferType) | 334 | DataStore::mainDatabase(d->transaction, bufferType) |
333 | .scan(uid, | 335 | .scan(uid, |
334 | [&](const QByteArray &key, const QByteArray &data) -> bool { | 336 | [&](const QByteArray &key, const QByteArray &data) -> bool { |
@@ -369,7 +371,7 @@ bool EntityStore::cleanupRevisions(qint64 revision) | |||
369 | const auto firstRevisionToCleanup = lastCleanRevision + 1; | 371 | const auto firstRevisionToCleanup = lastCleanRevision + 1; |
370 | bool cleanupIsNecessary = firstRevisionToCleanup <= revision; | 372 | bool cleanupIsNecessary = firstRevisionToCleanup <= revision; |
371 | if (cleanupIsNecessary) { | 373 | if (cleanupIsNecessary) { |
372 | SinkTrace() << "Cleaning up from " << firstRevisionToCleanup << " to " << revision; | 374 | SinkTraceCtx(d->logCtx) << "Cleaning up from " << firstRevisionToCleanup << " to " << revision; |
373 | for (qint64 rev = firstRevisionToCleanup; rev <= revision; rev++) { | 375 | for (qint64 rev = firstRevisionToCleanup; rev <= revision; rev++) { |
374 | cleanupRevision(revision); | 376 | cleanupRevision(revision); |
375 | } | 377 | } |
@@ -382,9 +384,9 @@ bool EntityStore::cleanupRevisions(qint64 revision) | |||
382 | 384 | ||
383 | QVector<QByteArray> EntityStore::fullScan(const QByteArray &type) | 385 | QVector<QByteArray> EntityStore::fullScan(const QByteArray &type) |
384 | { | 386 | { |
385 | SinkTrace() << "Looking for : " << type; | 387 | SinkTraceCtx(d->logCtx) << "Looking for : " << type; |
386 | if (!d->exists()) { | 388 | if (!d->exists()) { |
387 | SinkTrace() << "Database is not existing: " << type; | 389 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; |
388 | return QVector<QByteArray>(); | 390 | return QVector<QByteArray>(); |
389 | } | 391 | } |
390 | //The scan can return duplicate results if we have multiple revisions, so we use a set to deduplicate. | 392 | //The scan can return duplicate results if we have multiple revisions, so we use a set to deduplicate. |
@@ -395,21 +397,21 @@ QVector<QByteArray> EntityStore::fullScan(const QByteArray &type) | |||
395 | const auto uid = DataStore::uidFromKey(key); | 397 | const auto uid = DataStore::uidFromKey(key); |
396 | if (keys.contains(uid)) { | 398 | if (keys.contains(uid)) { |
397 | //Not something that should persist if the replay works, so we keep a message for now. | 399 | //Not something that should persist if the replay works, so we keep a message for now. |
398 | SinkTrace() << "Multiple revisions for key: " << key; | 400 | SinkTraceCtx(d->logCtx) << "Multiple revisions for key: " << key; |
399 | } | 401 | } |
400 | keys << uid; | 402 | keys << uid; |
401 | return true; | 403 | return true; |
402 | }, | 404 | }, |
403 | [](const DataStore::Error &error) { SinkWarning() << "Error during query: " << error.message; }); | 405 | [](const DataStore::Error &error) { SinkWarning() << "Error during query: " << error.message; }); |
404 | 406 | ||
405 | SinkTrace() << "Full scan retrieved " << keys.size() << " results."; | 407 | SinkTraceCtx(d->logCtx) << "Full scan retrieved " << keys.size() << " results."; |
406 | return keys.toList().toVector(); | 408 | return keys.toList().toVector(); |
407 | } | 409 | } |
408 | 410 | ||
409 | QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QueryBase &query, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting) | 411 | QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QueryBase &query, QSet<QByteArray> &appliedFilters, QByteArray &appliedSorting) |
410 | { | 412 | { |
411 | if (!d->exists()) { | 413 | if (!d->exists()) { |
412 | SinkTrace() << "Database is not existing: " << type; | 414 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; |
413 | return QVector<QByteArray>(); | 415 | return QVector<QByteArray>(); |
414 | } | 416 | } |
415 | return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction()); | 417 | return d->typeIndex(type).query(query, appliedFilters, appliedSorting, d->getTransaction()); |
@@ -418,7 +420,7 @@ QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const Query | |||
418 | QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) | 420 | QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value) |
419 | { | 421 | { |
420 | if (!d->exists()) { | 422 | if (!d->exists()) { |
421 | SinkTrace() << "Database is not existing: " << type; | 423 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; |
422 | return QVector<QByteArray>(); | 424 | return QVector<QByteArray>(); |
423 | } | 425 | } |
424 | return d->typeIndex(type).lookup(property, value, d->getTransaction()); | 426 | return d->typeIndex(type).lookup(property, value, d->getTransaction()); |
@@ -427,7 +429,7 @@ QVector<QByteArray> EntityStore::indexLookup(const QByteArray &type, const QByte | |||
427 | void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function<void(const QByteArray &uid)> &callback) | 429 | void EntityStore::indexLookup(const QByteArray &type, const QByteArray &property, const QVariant &value, const std::function<void(const QByteArray &uid)> &callback) |
428 | { | 430 | { |
429 | if (!d->exists()) { | 431 | if (!d->exists()) { |
430 | SinkTrace() << "Database is not existing: " << type; | 432 | SinkTraceCtx(d->logCtx) << "Database is not existing: " << type; |
431 | return; | 433 | return; |
432 | } | 434 | } |
433 | auto list = d->typeIndex(type).lookup(property, value, d->getTransaction()); | 435 | auto list = d->typeIndex(type).lookup(property, value, d->getTransaction()); |
@@ -595,7 +597,7 @@ bool EntityStore::contains(const QByteArray &type, const QByteArray &uid) | |||
595 | qint64 EntityStore::maxRevision() | 597 | qint64 EntityStore::maxRevision() |
596 | { | 598 | { |
597 | if (!d->exists()) { | 599 | if (!d->exists()) { |
598 | SinkTrace() << "Database is not existing."; | 600 | SinkTraceCtx(d->logCtx) << "Database is not existing."; |
599 | return 0; | 601 | return 0; |
600 | } | 602 | } |
601 | return DataStore::maxRevision(d->getTransaction()); | 603 | return DataStore::maxRevision(d->getTransaction()); |
@@ -623,3 +625,8 @@ qint64 EntityStore::maxRevision() | |||
623 | /* } */ | 625 | /* } */ |
624 | /* return transaction; */ | 626 | /* return transaction; */ |
625 | /* } */ | 627 | /* } */ |
628 | |||
629 | Sink::Log::Context EntityStore::logContext() const | ||
630 | { | ||
631 | return d->logCtx; | ||
632 | } | ||
diff --git a/common/storage/entitystore.h b/common/storage/entitystore.h index c626ebc..b8e1065 100644 --- a/common/storage/entitystore.h +++ b/common/storage/entitystore.h | |||
@@ -36,7 +36,7 @@ class SINK_EXPORT EntityStore | |||
36 | { | 36 | { |
37 | public: | 37 | public: |
38 | typedef QSharedPointer<EntityStore> Ptr; | 38 | typedef QSharedPointer<EntityStore> Ptr; |
39 | EntityStore(const ResourceContext &resourceContext); | 39 | EntityStore(const ResourceContext &resourceContext, const Sink::Log::Context &); |
40 | 40 | ||
41 | typedef std::function<void(const ApplicationDomain::ApplicationDomainType &, ApplicationDomain::ApplicationDomainType &)> PreprocessModification; | 41 | typedef std::function<void(const ApplicationDomain::ApplicationDomainType &, ApplicationDomain::ApplicationDomainType &)> PreprocessModification; |
42 | typedef std::function<void(ApplicationDomain::ApplicationDomainType &)> PreprocessCreation; | 42 | typedef std::function<void(ApplicationDomain::ApplicationDomainType &)> PreprocessCreation; |
@@ -109,6 +109,8 @@ public: | |||
109 | 109 | ||
110 | qint64 maxRevision(); | 110 | qint64 maxRevision(); |
111 | 111 | ||
112 | Sink::Log::Context logContext() const; | ||
113 | |||
112 | private: | 114 | private: |
113 | void copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision); | 115 | void copyBlobs(ApplicationDomain::ApplicationDomainType &entity, qint64 newRevision); |
114 | class Private; | 116 | class Private; |
diff --git a/common/store.cpp b/common/store.cpp index a70be05..8007626 100644 --- a/common/store.cpp +++ b/common/store.cpp | |||
@@ -107,20 +107,21 @@ static QMap<QByteArray, QByteArray> getResources(const Sink::Query::Filter &quer | |||
107 | 107 | ||
108 | 108 | ||
109 | template <class DomainType> | 109 | template <class DomainType> |
110 | KAsync::Job<void> queryResource(const QByteArray resourceType, const QByteArray &resourceInstanceIdentifier, const Query &query, typename AggregatingResultEmitter<typename DomainType::Ptr>::Ptr aggregatingEmitter) | 110 | KAsync::Job<void> queryResource(const QByteArray resourceType, const QByteArray &resourceInstanceIdentifier, const Query &query, typename AggregatingResultEmitter<typename DomainType::Ptr>::Ptr aggregatingEmitter, const Sink::Log::Context &ctx_) |
111 | { | 111 | { |
112 | auto ctx = ctx_.subContext(resourceInstanceIdentifier); | ||
112 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); | 113 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); |
113 | if (facade) { | 114 | if (facade) { |
114 | SinkTrace() << "Trying to fetch from resource " << resourceInstanceIdentifier; | 115 | SinkTraceCtx(ctx) << "Trying to fetch from resource " << resourceInstanceIdentifier; |
115 | auto result = facade->load(query); | 116 | auto result = facade->load(query, ctx); |
116 | if (result.second) { | 117 | if (result.second) { |
117 | aggregatingEmitter->addEmitter(result.second); | 118 | aggregatingEmitter->addEmitter(result.second); |
118 | } else { | 119 | } else { |
119 | SinkWarning() << "Null emitter for resource " << resourceInstanceIdentifier; | 120 | SinkWarningCtx(ctx) << "Null emitter for resource " << resourceInstanceIdentifier; |
120 | } | 121 | } |
121 | return result.first; | 122 | return result.first; |
122 | } else { | 123 | } else { |
123 | SinkTrace() << "Couldn' find a facade for " << resourceInstanceIdentifier; | 124 | SinkTraceCtx(ctx) << "Couldn' find a facade for " << resourceInstanceIdentifier; |
124 | // Ignore the error and carry on | 125 | // Ignore the error and carry on |
125 | return KAsync::null<void>(); | 126 | return KAsync::null<void>(); |
126 | } | 127 | } |
@@ -129,8 +130,9 @@ KAsync::Job<void> queryResource(const QByteArray resourceType, const QByteArray | |||
129 | template <class DomainType> | 130 | template <class DomainType> |
130 | QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | 131 | QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) |
131 | { | 132 | { |
133 | Log::Context ctx{query.id()}; | ||
132 | query.setType(ApplicationDomain::getTypeName<DomainType>()); | 134 | query.setType(ApplicationDomain::getTypeName<DomainType>()); |
133 | SinkTrace() << "Loading model: " << query; | 135 | SinkTraceCtx(ctx) << "Loading model: " << query; |
134 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr>>::create(query, query.requestedProperties); | 136 | auto model = QSharedPointer<ModelResult<DomainType, typename DomainType::Ptr>>::create(query, query.requestedProperties); |
135 | 137 | ||
136 | //* Client defines lifetime of model | 138 | //* Client defines lifetime of model |
@@ -145,18 +147,19 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
145 | model->setEmitter(aggregatingEmitter); | 147 | model->setEmitter(aggregatingEmitter); |
146 | 148 | ||
147 | if (query.liveQuery() && query.getResourceFilter().ids.isEmpty() && !ApplicationDomain::isGlobalType(ApplicationDomain::getTypeName<DomainType>())) { | 149 | if (query.liveQuery() && query.getResourceFilter().ids.isEmpty() && !ApplicationDomain::isGlobalType(ApplicationDomain::getTypeName<DomainType>())) { |
148 | SinkTrace() << "Listening for new resources"; | 150 | SinkTraceCtx(ctx) << "Listening for new resources"; |
151 | auto resourceCtx = ctx.subContext("resourceQuery"); | ||
149 | auto facade = FacadeFactory::instance().getFacade<ApplicationDomain::SinkResource>(); | 152 | auto facade = FacadeFactory::instance().getFacade<ApplicationDomain::SinkResource>(); |
150 | Q_ASSERT(facade); | 153 | Q_ASSERT(facade); |
151 | Sink::Query resourceQuery; | 154 | Sink::Query resourceQuery; |
152 | query.setFlags(Query::LiveQuery); | 155 | query.setFlags(Query::LiveQuery); |
153 | auto result = facade->load(resourceQuery); | 156 | auto result = facade->load(resourceQuery, resourceCtx); |
154 | auto emitter = result.second; | 157 | auto emitter = result.second; |
155 | emitter->onAdded([query, aggregatingEmitter](const ApplicationDomain::SinkResource::Ptr &resource) { | 158 | emitter->onAdded([query, aggregatingEmitter, resourceCtx](const ApplicationDomain::SinkResource::Ptr &resource) { |
156 | SinkTrace() << "Found new resources: " << resource->identifier(); | 159 | SinkTraceCtx(resourceCtx) << "Found new resources: " << resource->identifier(); |
157 | const auto resourceType = ResourceConfig::getResourceType(resource->identifier()); | 160 | const auto resourceType = ResourceConfig::getResourceType(resource->identifier()); |
158 | Q_ASSERT(!resourceType.isEmpty()); | 161 | Q_ASSERT(!resourceType.isEmpty()); |
159 | queryResource<DomainType>(resourceType, resource->identifier(), query, aggregatingEmitter).exec(); | 162 | queryResource<DomainType>(resourceType, resource->identifier(), query, aggregatingEmitter, resourceCtx).exec(); |
160 | }); | 163 | }); |
161 | emitter->onModified([](const ApplicationDomain::SinkResource::Ptr &) { | 164 | emitter->onModified([](const ApplicationDomain::SinkResource::Ptr &) { |
162 | }); | 165 | }); |
@@ -164,8 +167,8 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
164 | }); | 167 | }); |
165 | emitter->onInitialResultSetComplete([](const ApplicationDomain::SinkResource::Ptr &, bool) { | 168 | emitter->onInitialResultSetComplete([](const ApplicationDomain::SinkResource::Ptr &, bool) { |
166 | }); | 169 | }); |
167 | emitter->onComplete([query, aggregatingEmitter]() { | 170 | emitter->onComplete([query, aggregatingEmitter, resourceCtx]() { |
168 | SinkTrace() << "Resource query complete"; | 171 | SinkTraceCtx(resourceCtx) << "Resource query complete"; |
169 | 172 | ||
170 | }); | 173 | }); |
171 | model->setProperty("resourceEmitter", QVariant::fromValue(emitter)); | 174 | model->setProperty("resourceEmitter", QVariant::fromValue(emitter)); |
@@ -173,9 +176,9 @@ QSharedPointer<QAbstractItemModel> Store::loadModel(Query query) | |||
173 | } | 176 | } |
174 | 177 | ||
175 | KAsync::value(resources.keys()) | 178 | KAsync::value(resources.keys()) |
176 | .template each([query, aggregatingEmitter, resources](const QByteArray &resourceInstanceIdentifier) { | 179 | .template each([query, aggregatingEmitter, resources, ctx](const QByteArray &resourceInstanceIdentifier) { |
177 | const auto resourceType = resources.value(resourceInstanceIdentifier); | 180 | const auto resourceType = resources.value(resourceInstanceIdentifier); |
178 | return queryResource<DomainType>(resourceType, resourceInstanceIdentifier, query, aggregatingEmitter); | 181 | return queryResource<DomainType>(resourceType, resourceInstanceIdentifier, query, aggregatingEmitter, ctx); |
179 | }) | 182 | }) |
180 | .exec(); | 183 | .exec(); |
181 | model->fetchMore(QModelIndex()); | 184 | model->fetchMore(QModelIndex()); |
@@ -370,30 +373,31 @@ DomainType Store::readOne(const Sink::Query &query) | |||
370 | template <class DomainType> | 373 | template <class DomainType> |
371 | QList<DomainType> Store::read(const Sink::Query &q) | 374 | QList<DomainType> Store::read(const Sink::Query &q) |
372 | { | 375 | { |
376 | Log::Context ctx{q.id()}; | ||
373 | auto query = q; | 377 | auto query = q; |
374 | query.setFlags(Query::SynchronousQuery); | 378 | query.setFlags(Query::SynchronousQuery); |
375 | QList<DomainType> list; | 379 | QList<DomainType> list; |
376 | auto resources = getResources(query.getResourceFilter(), ApplicationDomain::getTypeName<DomainType>()); | 380 | auto resources = getResources(query.getResourceFilter(), ApplicationDomain::getTypeName<DomainType>()); |
377 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); | 381 | auto aggregatingEmitter = AggregatingResultEmitter<typename DomainType::Ptr>::Ptr::create(); |
378 | aggregatingEmitter->onAdded([&list](const typename DomainType::Ptr &value){ | 382 | aggregatingEmitter->onAdded([&list, ctx](const typename DomainType::Ptr &value){ |
379 | SinkTrace() << "Found value: " << value->identifier(); | 383 | SinkTraceCtx(ctx) << "Found value: " << value->identifier(); |
380 | list << *value; | 384 | list << *value; |
381 | }); | 385 | }); |
382 | for (const auto &resourceInstanceIdentifier : resources.keys()) { | 386 | for (const auto &resourceInstanceIdentifier : resources.keys()) { |
383 | const auto resourceType = resources.value(resourceInstanceIdentifier); | 387 | const auto resourceType = resources.value(resourceInstanceIdentifier); |
384 | SinkTrace() << "Querying resource: " << resourceType << resourceInstanceIdentifier; | 388 | SinkTraceCtx(ctx) << "Querying resource: " << resourceType << resourceInstanceIdentifier; |
385 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); | 389 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceType, resourceInstanceIdentifier); |
386 | if (facade) { | 390 | if (facade) { |
387 | SinkTrace() << "Trying to fetch from resource " << resourceInstanceIdentifier; | 391 | SinkTraceCtx(ctx) << "Trying to fetch from resource " << resourceInstanceIdentifier; |
388 | auto result = facade->load(query); | 392 | auto result = facade->load(query, ctx); |
389 | if (result.second) { | 393 | if (result.second) { |
390 | aggregatingEmitter->addEmitter(result.second); | 394 | aggregatingEmitter->addEmitter(result.second); |
391 | } else { | 395 | } else { |
392 | SinkWarning() << "Null emitter for resource " << resourceInstanceIdentifier; | 396 | SinkWarningCtx(ctx) << "Null emitter for resource " << resourceInstanceIdentifier; |
393 | } | 397 | } |
394 | result.first.exec(); | 398 | result.first.exec(); |
395 | } else { | 399 | } else { |
396 | SinkTrace() << "Couldn't find a facade for " << resourceInstanceIdentifier; | 400 | SinkTraceCtx(ctx) << "Couldn't find a facade for " << resourceInstanceIdentifier; |
397 | // Ignore the error and carry on | 401 | // Ignore the error and carry on |
398 | } | 402 | } |
399 | } | 403 | } |
diff --git a/common/synchronizer.cpp b/common/synchronizer.cpp index d94eb43..ed493dc 100644 --- a/common/synchronizer.cpp +++ b/common/synchronizer.cpp | |||
@@ -36,8 +36,9 @@ using namespace Sink; | |||
36 | 36 | ||
37 | Synchronizer::Synchronizer(const Sink::ResourceContext &context) | 37 | Synchronizer::Synchronizer(const Sink::ResourceContext &context) |
38 | : ChangeReplay(context), | 38 | : ChangeReplay(context), |
39 | mLogCtx{"synchronizer"}, | ||
39 | mResourceContext(context), | 40 | mResourceContext(context), |
40 | mEntityStore(Storage::EntityStore::Ptr::create(mResourceContext)), | 41 | mEntityStore(Storage::EntityStore::Ptr::create(mResourceContext, mLogCtx)), |
41 | mSyncStorage(Sink::storageLocation(), mResourceContext.instanceId() + ".synchronization", Sink::Storage::DataStore::DataStore::ReadWrite), | 42 | mSyncStorage(Sink::storageLocation(), mResourceContext.instanceId() + ".synchronization", Sink::Storage::DataStore::DataStore::ReadWrite), |
42 | mSyncInProgress(false) | 43 | mSyncInProgress(false) |
43 | { | 44 | { |
@@ -170,14 +171,14 @@ void Synchronizer::modifyIfChanged(Storage::EntityStore &store, const QByteArray | |||
170 | void Synchronizer::modify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) | 171 | void Synchronizer::modify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) |
171 | { | 172 | { |
172 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); | 173 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); |
173 | Storage::EntityStore store(mResourceContext); | 174 | Storage::EntityStore store(mResourceContext, mLogCtx); |
174 | modifyIfChanged(store, bufferType, sinkId, entity); | 175 | modifyIfChanged(store, bufferType, sinkId, entity); |
175 | } | 176 | } |
176 | 177 | ||
177 | void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) | 178 | void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray &remoteId, const Sink::ApplicationDomain::ApplicationDomainType &entity) |
178 | { | 179 | { |
179 | SinkTrace() << "Create or modify" << bufferType << remoteId; | 180 | SinkTrace() << "Create or modify" << bufferType << remoteId; |
180 | Storage::EntityStore store(mResourceContext); | 181 | Storage::EntityStore store(mResourceContext, mLogCtx); |
181 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); | 182 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); |
182 | const auto found = store.contains(bufferType, sinkId); | 183 | const auto found = store.contains(bufferType, sinkId); |
183 | if (!found) { | 184 | if (!found) { |
@@ -194,7 +195,7 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray | |||
194 | 195 | ||
195 | SinkTrace() << "Create or modify" << bufferType << remoteId; | 196 | SinkTrace() << "Create or modify" << bufferType << remoteId; |
196 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); | 197 | const auto sinkId = syncStore().resolveRemoteId(bufferType, remoteId); |
197 | Storage::EntityStore store(mResourceContext); | 198 | Storage::EntityStore store(mResourceContext, mLogCtx); |
198 | const auto found = store.contains(bufferType, sinkId); | 199 | const auto found = store.contains(bufferType, sinkId); |
199 | if (!found) { | 200 | if (!found) { |
200 | if (!mergeCriteria.isEmpty()) { | 201 | if (!mergeCriteria.isEmpty()) { |
@@ -203,7 +204,7 @@ void Synchronizer::createOrModify(const QByteArray &bufferType, const QByteArray | |||
203 | query.filter(it.key(), it.value()); | 204 | query.filter(it.key(), it.value()); |
204 | } | 205 | } |
205 | bool merge = false; | 206 | bool merge = false; |
206 | Storage::EntityStore store{mResourceContext}; | 207 | Storage::EntityStore store{mResourceContext, mLogCtx}; |
207 | DataStoreQuery dataStoreQuery{query, ApplicationDomain::getTypeName<DomainType>(), store}; | 208 | DataStoreQuery dataStoreQuery{query, ApplicationDomain::getTypeName<DomainType>(), store}; |
208 | auto resultSet = dataStoreQuery.execute(); | 209 | auto resultSet = dataStoreQuery.execute(); |
209 | resultSet.replaySet(0, 1, [this, &merge, bufferType, remoteId](const ResultSet::Result &r) { | 210 | resultSet.replaySet(0, 1, [this, &merge, bufferType, remoteId](const ResultSet::Result &r) { |
@@ -232,7 +233,7 @@ QByteArrayList Synchronizer::resolveFilter(const QueryBase::Comparator &filter) | |||
232 | result << filter.value.value<QByteArray>(); | 233 | result << filter.value.value<QByteArray>(); |
233 | } else if (filter.value.canConvert<QueryBase>()) { | 234 | } else if (filter.value.canConvert<QueryBase>()) { |
234 | auto query = filter.value.value<QueryBase>(); | 235 | auto query = filter.value.value<QueryBase>(); |
235 | Storage::EntityStore store{mResourceContext}; | 236 | Storage::EntityStore store{mResourceContext, mLogCtx}; |
236 | DataStoreQuery dataStoreQuery{query, query.type(), store}; | 237 | DataStoreQuery dataStoreQuery{query, query.type(), store}; |
237 | auto resultSet = dataStoreQuery.execute(); | 238 | auto resultSet = dataStoreQuery.execute(); |
238 | resultSet.replaySet(0, 0, [this, &result](const ResultSet::Result &r) { | 239 | resultSet.replaySet(0, 0, [this, &result](const ResultSet::Result &r) { |
diff --git a/common/synchronizer.h b/common/synchronizer.h index 00b5fba..2c56d6a 100644 --- a/common/synchronizer.h +++ b/common/synchronizer.h | |||
@@ -170,6 +170,7 @@ private: | |||
170 | void modifyIfChanged(Storage::EntityStore &store, const QByteArray &bufferType, const QByteArray &sinkId, const Sink::ApplicationDomain::ApplicationDomainType &entity); | 170 | void modifyIfChanged(Storage::EntityStore &store, const QByteArray &bufferType, const QByteArray &sinkId, const Sink::ApplicationDomain::ApplicationDomainType &entity); |
171 | KAsync::Job<void> processSyncQueue(); | 171 | KAsync::Job<void> processSyncQueue(); |
172 | 172 | ||
173 | Sink::Log::Context mLogCtx; | ||
173 | Sink::ResourceContext mResourceContext; | 174 | Sink::ResourceContext mResourceContext; |
174 | Sink::Storage::EntityStore::Ptr mEntityStore; | 175 | Sink::Storage::EntityStore::Ptr mEntityStore; |
175 | QSharedPointer<SynchronizerStore> mSyncStore; | 176 | QSharedPointer<SynchronizerStore> mSyncStore; |
diff --git a/common/test.cpp b/common/test.cpp index 71bb972..387fcda 100644 --- a/common/test.cpp +++ b/common/test.cpp | |||
@@ -141,7 +141,7 @@ public: | |||
141 | // mTestAccount->removeEntity<T>(domainObject); | 141 | // mTestAccount->removeEntity<T>(domainObject); |
142 | return KAsync::null<void>(); | 142 | return KAsync::null<void>(); |
143 | }; | 143 | }; |
144 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename T::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE | 144 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename T::Ptr>::Ptr> load(const Sink::Query &query, const Sink::Log::Context &) Q_DECL_OVERRIDE |
145 | { | 145 | { |
146 | auto resultProvider = new Sink::ResultProvider<typename T::Ptr>(); | 146 | auto resultProvider = new Sink::ResultProvider<typename T::Ptr>(); |
147 | resultProvider->onDone([resultProvider]() { | 147 | resultProvider->onDone([resultProvider]() { |
diff --git a/common/typeindex.cpp b/common/typeindex.cpp index 9d71463..077bfa1 100644 --- a/common/typeindex.cpp +++ b/common/typeindex.cpp | |||
@@ -57,7 +57,7 @@ static QByteArray toSortableByteArray(const QDateTime &date) | |||
57 | } | 57 | } |
58 | 58 | ||
59 | 59 | ||
60 | TypeIndex::TypeIndex(const QByteArray &type) : mType(type) | 60 | TypeIndex::TypeIndex(const QByteArray &type, const Sink::Log::Context &ctx) : mLogCtx(ctx), mType(type) |
61 | { | 61 | { |
62 | } | 62 | } |
63 | 63 | ||
@@ -73,7 +73,7 @@ template <> | |||
73 | void TypeIndex::addProperty<QByteArray>(const QByteArray &property) | 73 | void TypeIndex::addProperty<QByteArray>(const QByteArray &property) |
74 | { | 74 | { |
75 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { | 75 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { |
76 | // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray(); | 76 | // SinkTraceCtx(mLogCtx) << "Indexing " << mType + ".index." + property << value.toByteArray(); |
77 | Index(indexName(property), transaction).add(getByteArray(value), identifier); | 77 | Index(indexName(property), transaction).add(getByteArray(value), identifier); |
78 | }; | 78 | }; |
79 | mIndexer.insert(property, indexer); | 79 | mIndexer.insert(property, indexer); |
@@ -84,7 +84,7 @@ template <> | |||
84 | void TypeIndex::addProperty<QString>(const QByteArray &property) | 84 | void TypeIndex::addProperty<QString>(const QByteArray &property) |
85 | { | 85 | { |
86 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { | 86 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { |
87 | // SinkTrace() << "Indexing " << mType + ".index." + property << value.toByteArray(); | 87 | // SinkTraceCtx(mLogCtx) << "Indexing " << mType + ".index." + property << value.toByteArray(); |
88 | Index(indexName(property), transaction).add(getByteArray(value), identifier); | 88 | Index(indexName(property), transaction).add(getByteArray(value), identifier); |
89 | }; | 89 | }; |
90 | mIndexer.insert(property, indexer); | 90 | mIndexer.insert(property, indexer); |
@@ -95,7 +95,7 @@ template <> | |||
95 | void TypeIndex::addProperty<QDateTime>(const QByteArray &property) | 95 | void TypeIndex::addProperty<QDateTime>(const QByteArray &property) |
96 | { | 96 | { |
97 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { | 97 | auto indexer = [this, property](const QByteArray &identifier, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) { |
98 | //SinkTrace() << "Indexing " << mType + ".index." + property << getByteArray(value); | 98 | //SinkTraceCtx(mLogCtx) << "Indexing " << mType + ".index." + property << getByteArray(value); |
99 | Index(indexName(property), transaction).add(getByteArray(value), identifier); | 99 | Index(indexName(property), transaction).add(getByteArray(value), identifier); |
100 | }; | 100 | }; |
101 | mIndexer.insert(property, indexer); | 101 | mIndexer.insert(property, indexer); |
@@ -182,7 +182,7 @@ QVector<QByteArray> TypeIndex::query(const Sink::QueryBase &query, QSet<QByteArr | |||
182 | keys << indexLookup(index, query.getFilter(it.key())); | 182 | keys << indexLookup(index, query.getFilter(it.key())); |
183 | appliedFilters << it.key(); | 183 | appliedFilters << it.key(); |
184 | appliedSorting = it.value(); | 184 | appliedSorting = it.value(); |
185 | SinkTrace() << "Index lookup on " << it.key() << it.value() << " found " << keys.size() << " keys."; | 185 | SinkTraceCtx(mLogCtx) << "Index lookup on " << it.key() << it.value() << " found " << keys.size() << " keys."; |
186 | return keys; | 186 | return keys; |
187 | } | 187 | } |
188 | } | 188 | } |
@@ -191,24 +191,24 @@ QVector<QByteArray> TypeIndex::query(const Sink::QueryBase &query, QSet<QByteArr | |||
191 | Index index(indexName(property), transaction); | 191 | Index index(indexName(property), transaction); |
192 | keys << indexLookup(index, query.getFilter(property)); | 192 | keys << indexLookup(index, query.getFilter(property)); |
193 | appliedFilters << property; | 193 | appliedFilters << property; |
194 | SinkTrace() << "Index lookup on " << property << " found " << keys.size() << " keys."; | 194 | SinkTraceCtx(mLogCtx) << "Index lookup on " << property << " found " << keys.size() << " keys."; |
195 | return keys; | 195 | return keys; |
196 | } | 196 | } |
197 | } | 197 | } |
198 | SinkTrace() << "No matching index"; | 198 | SinkTraceCtx(mLogCtx) << "No matching index"; |
199 | return keys; | 199 | return keys; |
200 | } | 200 | } |
201 | 201 | ||
202 | QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) | 202 | QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant &value, Sink::Storage::DataStore::Transaction &transaction) |
203 | { | 203 | { |
204 | SinkTrace() << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; | 204 | SinkTraceCtx(mLogCtx) << "Index lookup on property: " << property << mSecondaryProperties.keys() << mProperties; |
205 | if (mProperties.contains(property)) { | 205 | if (mProperties.contains(property)) { |
206 | QVector<QByteArray> keys; | 206 | QVector<QByteArray> keys; |
207 | Index index(indexName(property), transaction); | 207 | Index index(indexName(property), transaction); |
208 | const auto lookupKey = getByteArray(value); | 208 | const auto lookupKey = getByteArray(value); |
209 | index.lookup( | 209 | index.lookup( |
210 | lookupKey, [&, this](const QByteArray &value) { keys << value; }, [property, this](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; }); | 210 | lookupKey, [&, this](const QByteArray &value) { keys << value; }, [property, this](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; }); |
211 | SinkTrace() << "Index lookup on " << property << " found " << keys.size() << " keys."; | 211 | SinkTraceCtx(mLogCtx) << "Index lookup on " << property << " found " << keys.size() << " keys."; |
212 | return keys; | 212 | return keys; |
213 | } else if (mSecondaryProperties.contains(property)) { | 213 | } else if (mSecondaryProperties.contains(property)) { |
214 | //Lookups on secondary indexes first lookup the key, and then lookup the results again to resolve to entity id's | 214 | //Lookups on secondary indexes first lookup the key, and then lookup the results again to resolve to entity id's |
@@ -220,7 +220,7 @@ QVector<QByteArray> TypeIndex::lookup(const QByteArray &property, const QVariant | |||
220 | const auto lookupKey = getByteArray(value); | 220 | const auto lookupKey = getByteArray(value); |
221 | index.lookup( | 221 | index.lookup( |
222 | lookupKey, [&, this](const QByteArray &value) { secondaryKeys << value; }, [property, this](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; }); | 222 | lookupKey, [&, this](const QByteArray &value) { secondaryKeys << value; }, [property, this](const Index::Error &error) { SinkWarning() << "Error in index: " << error.message << property; }); |
223 | SinkTrace() << "Looked up secondary keys: " << secondaryKeys; | 223 | SinkTraceCtx(mLogCtx) << "Looked up secondary keys: " << secondaryKeys; |
224 | for (const auto &secondary : secondaryKeys) { | 224 | for (const auto &secondary : secondaryKeys) { |
225 | keys += lookup(resultProperty, secondary, transaction); | 225 | keys += lookup(resultProperty, secondary, transaction); |
226 | } | 226 | } |
diff --git a/common/typeindex.h b/common/typeindex.h index b1aec38..626959e 100644 --- a/common/typeindex.h +++ b/common/typeindex.h | |||
@@ -34,7 +34,7 @@ namespace Storage { | |||
34 | class TypeIndex | 34 | class TypeIndex |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | TypeIndex(const QByteArray &type); | 37 | TypeIndex(const QByteArray &type, const Sink::Log::Context &); |
38 | 38 | ||
39 | template <typename T> | 39 | template <typename T> |
40 | void addProperty(const QByteArray &property); | 40 | void addProperty(const QByteArray &property); |
@@ -93,8 +93,8 @@ public: | |||
93 | private: | 93 | private: |
94 | friend class Sink::Storage::EntityStore; | 94 | friend class Sink::Storage::EntityStore; |
95 | QByteArray indexName(const QByteArray &property, const QByteArray &sortProperty = QByteArray()) const; | 95 | QByteArray indexName(const QByteArray &property, const QByteArray &sortProperty = QByteArray()) const; |
96 | Sink::Log::Context mLogCtx; | ||
96 | QByteArray mType; | 97 | QByteArray mType; |
97 | SINK_DEBUG_COMPONENT(mType) | ||
98 | QByteArrayList mProperties; | 98 | QByteArrayList mProperties; |
99 | QMap<QByteArray, QByteArray> mSortedProperties; | 99 | QMap<QByteArray, QByteArray> mSortedProperties; |
100 | //<Property, ResultProperty> | 100 | //<Property, ResultProperty> |
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index e16a8d7..7d71136 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -579,7 +579,7 @@ protected: | |||
579 | auto mainStore = QSharedPointer<Sink::Storage::DataStore>::create(Sink::storageLocation(), mResourceContext.instanceId(), Sink::Storage::DataStore::ReadOnly); | 579 | auto mainStore = QSharedPointer<Sink::Storage::DataStore>::create(Sink::storageLocation(), mResourceContext.instanceId(), Sink::Storage::DataStore::ReadOnly); |
580 | auto transaction = mainStore->createTransaction(Sink::Storage::DataStore::ReadOnly); | 580 | auto transaction = mainStore->createTransaction(Sink::Storage::DataStore::ReadOnly); |
581 | 581 | ||
582 | Sink::Storage::EntityStore entityStore(mResourceContext); | 582 | Sink::Storage::EntityStore entityStore(mResourceContext, {"imapresource"}); |
583 | auto syncStore = QSharedPointer<Sink::SynchronizerStore>::create(synchronizationTransaction); | 583 | auto syncStore = QSharedPointer<Sink::SynchronizerStore>::create(synchronizationTransaction); |
584 | 584 | ||
585 | SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; | 585 | SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; |
diff --git a/examples/maildirresource/facade.cpp b/examples/maildirresource/facade.cpp index d26b86c..13ceaaf 100644 --- a/examples/maildirresource/facade.cpp +++ b/examples/maildirresource/facade.cpp | |||
@@ -55,11 +55,6 @@ MaildirResourceMailFacade::~MaildirResourceMailFacade() | |||
55 | { | 55 | { |
56 | } | 56 | } |
57 | 57 | ||
58 | QPair<KAsync::Job<void>, Sink::ResultEmitter<Sink::ApplicationDomain::Mail::Ptr>::Ptr> MaildirResourceMailFacade::load(const Sink::Query &query) | ||
59 | { | ||
60 | return Sink::GenericFacade<Sink::ApplicationDomain::Mail>::load(query); | ||
61 | } | ||
62 | |||
63 | 58 | ||
64 | MaildirResourceFolderFacade::MaildirResourceFolderFacade(const Sink::ResourceContext &context) | 59 | MaildirResourceFolderFacade::MaildirResourceFolderFacade(const Sink::ResourceContext &context) |
65 | : Sink::GenericFacade<Sink::ApplicationDomain::Folder>(context) | 60 | : Sink::GenericFacade<Sink::ApplicationDomain::Folder>(context) |
diff --git a/examples/maildirresource/facade.h b/examples/maildirresource/facade.h index fdb693e..6b96fef 100644 --- a/examples/maildirresource/facade.h +++ b/examples/maildirresource/facade.h | |||
@@ -26,7 +26,6 @@ class MaildirResourceMailFacade : public Sink::GenericFacade<Sink::ApplicationDo | |||
26 | public: | 26 | public: |
27 | MaildirResourceMailFacade(const Sink::ResourceContext &context); | 27 | MaildirResourceMailFacade(const Sink::ResourceContext &context); |
28 | virtual ~MaildirResourceMailFacade(); | 28 | virtual ~MaildirResourceMailFacade(); |
29 | QPair<KAsync::Job<void>, Sink::ResultEmitter<Sink::ApplicationDomain::Mail::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE; | ||
30 | }; | 29 | }; |
31 | 30 | ||
32 | class MaildirResourceFolderFacade : public Sink::GenericFacade<Sink::ApplicationDomain::Folder> | 31 | class MaildirResourceFolderFacade : public Sink::GenericFacade<Sink::ApplicationDomain::Folder> |
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 997ddef..b64e8d3 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -454,7 +454,7 @@ protected: | |||
454 | auto mainStore = QSharedPointer<Sink::Storage::DataStore>::create(Sink::storageLocation(), mResourceContext.instanceId(), Sink::Storage::DataStore::ReadOnly); | 454 | auto mainStore = QSharedPointer<Sink::Storage::DataStore>::create(Sink::storageLocation(), mResourceContext.instanceId(), Sink::Storage::DataStore::ReadOnly); |
455 | auto transaction = mainStore->createTransaction(Sink::Storage::DataStore::ReadOnly); | 455 | auto transaction = mainStore->createTransaction(Sink::Storage::DataStore::ReadOnly); |
456 | 456 | ||
457 | Sink::Storage::EntityStore entityStore(mResourceContext); | 457 | Sink::Storage::EntityStore entityStore(mResourceContext, {"maildirresource"}); |
458 | auto syncStore = QSharedPointer<SynchronizerStore>::create(synchronizationTransaction); | 458 | auto syncStore = QSharedPointer<SynchronizerStore>::create(synchronizationTransaction); |
459 | 459 | ||
460 | SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; | 460 | SinkTrace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; |
diff --git a/sinksh/syntax_modules/sink_list.cpp b/sinksh/syntax_modules/sink_list.cpp index 1e15dd3..dd1498f 100644 --- a/sinksh/syntax_modules/sink_list.cpp +++ b/sinksh/syntax_modules/sink_list.cpp | |||
@@ -80,6 +80,7 @@ bool list(const QStringList &args_, State &state) | |||
80 | } | 80 | } |
81 | 81 | ||
82 | Sink::Query query; | 82 | Sink::Query query; |
83 | query.setId("list"); | ||
83 | 84 | ||
84 | if (options.options.contains("resource")) { | 85 | if (options.options.contains("resource")) { |
85 | query.resourceFilter(baIfAvailable(options.options.value("resource"))); | 86 | query.resourceFilter(baIfAvailable(options.options.value("resource"))); |
diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index d2fb747..544b981 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp | |||
@@ -53,28 +53,28 @@ public: | |||
53 | { | 53 | { |
54 | return KAsync::null<void>(); | 54 | return KAsync::null<void>(); |
55 | }; | 55 | }; |
56 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename T::Ptr>::Ptr> load(const Sink::Query &query) Q_DECL_OVERRIDE | 56 | QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename T::Ptr>::Ptr> load(const Sink::Query &query, const Sink::Log::Context &ctx) Q_DECL_OVERRIDE |
57 | { | 57 | { |
58 | auto resultProvider = new Sink::ResultProvider<typename T::Ptr>(); | 58 | auto resultProvider = new Sink::ResultProvider<typename T::Ptr>(); |
59 | resultProvider->onDone([resultProvider]() { | 59 | resultProvider->onDone([resultProvider,ctx]() { |
60 | SinkTrace() << "Result provider is done"; | 60 | SinkTraceCtx(ctx) << "Result provider is done"; |
61 | delete resultProvider; | 61 | delete resultProvider; |
62 | }); | 62 | }); |
63 | // We have to do it this way, otherwise we're not setting the fetcher right | 63 | // We have to do it this way, otherwise we're not setting the fetcher right |
64 | auto emitter = resultProvider->emitter(); | 64 | auto emitter = resultProvider->emitter(); |
65 | 65 | ||
66 | resultProvider->setFetcher([query, resultProvider, this](const typename T::Ptr &parent) { | 66 | resultProvider->setFetcher([query, resultProvider, this, ctx](const typename T::Ptr &parent) { |
67 | if (parent) { | 67 | if (parent) { |
68 | SinkTrace() << "Running the fetcher " << parent->identifier(); | 68 | SinkTraceCtx(ctx) << "Running the fetcher " << parent->identifier(); |
69 | } else { | 69 | } else { |
70 | SinkTrace() << "Running the fetcher."; | 70 | SinkTraceCtx(ctx) << "Running the fetcher."; |
71 | } | 71 | } |
72 | SinkTrace() << "-------------------------."; | 72 | SinkTraceCtx(ctx) << "-------------------------."; |
73 | for (const auto &res : results) { | 73 | for (const auto &res : results) { |
74 | qDebug() << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); | 74 | SinkTraceCtx(ctx) << "Parent filter " << query.getFilter("parent").value.toByteArray() << res->identifier() << res->getProperty("parent").toByteArray(); |
75 | auto parentProperty = res->getProperty("parent").toByteArray(); | 75 | auto parentProperty = res->getProperty("parent").toByteArray(); |
76 | if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty().isEmpty()) { | 76 | if ((!parent && parentProperty.isEmpty()) || (parent && parentProperty == parent->identifier()) || query.parentProperty().isEmpty()) { |
77 | qDebug() << "Found a hit" << res->identifier(); | 77 | SinkTraceCtx(ctx) << "Found a hit" << res->identifier(); |
78 | resultProvider->add(res); | 78 | resultProvider->add(res); |
79 | } | 79 | } |
80 | } | 80 | } |
diff --git a/tests/databasepopulationandfacadequerybenchmark.cpp b/tests/databasepopulationandfacadequerybenchmark.cpp index 6bd2051..48c4738 100644 --- a/tests/databasepopulationandfacadequerybenchmark.cpp +++ b/tests/databasepopulationandfacadequerybenchmark.cpp | |||
@@ -106,7 +106,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject | |||
106 | context.mResourceAccess = resourceAccess; | 106 | context.mResourceAccess = resourceAccess; |
107 | TestResourceFacade facade(context); | 107 | TestResourceFacade facade(context); |
108 | 108 | ||
109 | auto ret = facade.load(query); | 109 | auto ret = facade.load(query, Sink::Log::Context{"benchmark"}); |
110 | ret.first.exec().waitForFinished(); | 110 | ret.first.exec().waitForFinished(); |
111 | auto emitter = ret.second; | 111 | auto emitter = ret.second; |
112 | QList<Sink::ApplicationDomain::Event::Ptr> list; | 112 | QList<Sink::ApplicationDomain::Event::Ptr> list; |
diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index d3598b2..e55e744 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp | |||
@@ -84,7 +84,6 @@ class MailQueryBenchmark : public QObject | |||
84 | { | 84 | { |
85 | const auto startingRss = getCurrentRSS(); | 85 | const auto startingRss = getCurrentRSS(); |
86 | 86 | ||
87 | |||
88 | // Benchmark | 87 | // Benchmark |
89 | QTime time; | 88 | QTime time; |
90 | time.start(); | 89 | time.start(); |
@@ -93,7 +92,7 @@ class MailQueryBenchmark : public QObject | |||
93 | context.mResourceAccess = QSharedPointer<TestResourceAccess>::create(); | 92 | context.mResourceAccess = QSharedPointer<TestResourceAccess>::create(); |
94 | TestMailResourceFacade facade(context); | 93 | TestMailResourceFacade facade(context); |
95 | 94 | ||
96 | auto ret = facade.load(query); | 95 | auto ret = facade.load(query, Sink::Log::Context{"benchmark"}); |
97 | ret.first.exec().waitForFinished(); | 96 | ret.first.exec().waitForFinished(); |
98 | auto emitter = ret.second; | 97 | auto emitter = ret.second; |
99 | QList<Mail::Ptr> list; | 98 | QList<Mail::Ptr> list; |