Rather than waiting for active uploads - monitor the current storage size and keep trying while there's still time left to upload whatever is there. This is equivalent to v1 behavior.

This commit is contained in:
Max Golovanov 2018-08-31 22:02:32 -07:00
Родитель 114d6563c6
Коммит 1afa52c8de
11 изменённых файлов: 49 добавлений и 21 удалений

Просмотреть файл

@ -20,7 +20,7 @@
#endif
#include "DebugCallback.hpp"
LOGMANAGER_INSTANCE
#define TOKEN "6d084bbf6a9644ef83f40a77c9e34580-c2d379e0-4408-4325-9b4d-2a7d78131e14-7322"
@ -220,23 +220,27 @@ int main()
#if 1
// LogManager::PauseTransmission();
logger->LogEvent("TestEvent");
// LogManager::Flush();
#endif
Api_v1_CompatChecks();
// Api_v1_CompatChecks();
printf("LogManager::GetSemanticContext \n");
ISemanticContext* semanticContext = LogManager::GetSemanticContext();
// Ingest events of various latencies
printf("Starting stress-test...\n");
for(size_t i = 1; i <= MAX_EVENTS_TO_LOG; i++)
{
std::string eventName("ariasdk_test_linktest");
EventLatency latency = (EventLatency)(1 + i % (unsigned)EventLatency_RealTime);
std::string eventName("sample_event_lat");
eventName += std::to_string((unsigned)latency);
EventProperties event(eventName);
event.SetProperty("result", "Success");
event.SetProperty("random", rand());
event.SetProperty("secret", 5.6872);
event.SetProperty("seq", (uint64_t)i);
event.SetLatency(latency);
logger->LogEvent(event);
}
@ -245,9 +249,6 @@ int main()
// normal - 4 sec
// low - 8 sec
printf("LogManager::UploadNow\n");
LogManager::UploadNow();
printf("LogManager::FlushAndTeardown\n");
LogManager::FlushAndTeardown();

Просмотреть файл

@ -247,7 +247,7 @@ namespace ARIASDK_NS_BEGIN {
/// Get current Db size returned. Called from the internal worker thread.
/// </remarks>
/// <returns>Value of the requested DB size</returns>
virtual unsigned GetSize() = 0;
virtual size_t GetSize() = 0;
/// <summary>
/// Get Vector of records from DB

Просмотреть файл

@ -336,7 +336,7 @@ namespace ARIASDK_NS_BEGIN {
/// <remarks>
/// Called from the internal worker thread.
/// </remarks>
unsigned MemoryStorage::GetSize()
size_t MemoryStorage::GetSize()
{
return m_size.load();
}

Просмотреть файл

@ -51,7 +51,7 @@ namespace ARIASDK_NS_BEGIN {
virtual std::string GetSetting(std::string const& name) override;
virtual unsigned GetSize() override;
virtual size_t GetSize() override;
virtual size_t GetRecordCount();

Просмотреть файл

@ -102,11 +102,24 @@ namespace ARIASDK_NS_BEGIN {
m_offlineStorageDisk->Shutdown();
}
}
unsigned OfflineStorageHandler::GetSize()
/// <summary>
/// Get estimated DB size
/// </summary>
/// <returns>
/// Size of memory + disk storage
/// </returns>
/// <remarks>
/// Value may change at runtime, so it's only approximate value.
/// </remarks>
size_t OfflineStorageHandler::GetSize()
{
// TODO: [MG] - add sum of memory + offline
return 0;
size_t size = 0;
if (m_offlineStorageMemory != nullptr)
size += m_offlineStorageMemory->GetSize();
if (m_offlineStorageDisk != nullptr)
size += m_offlineStorageDisk->GetSize();
return size;
}
void OfflineStorageHandler::Flush()

Просмотреть файл

@ -32,7 +32,7 @@ namespace ARIASDK_NS_BEGIN {
virtual bool StoreSetting(std::string const& name, std::string const& value) override;
virtual std::string GetSetting(std::string const& name) override;
virtual unsigned GetSize() override;
virtual size_t GetSize() override;
virtual std::vector<StorageRecord>* GetRecords(bool shutdown, EventLatency minLatency = EventLatency_Unspecified, unsigned maxCount = 0) override;
virtual bool ResizeDb() override;

Просмотреть файл

@ -803,7 +803,7 @@ namespace ARIASDK_NS_BEGIN {
#endif
// TODO: [MG] - for on-disk database this has to be replaced by filesize check
unsigned OfflineStorage_SQLite::GetSize()
size_t OfflineStorage_SQLite::GetSize()
{
LOCKGUARD(m_lock);
unsigned pageCount;
@ -811,11 +811,11 @@ namespace ARIASDK_NS_BEGIN {
while (!pageCountStmt.select())
{
PAL::sleep(100);
}
}
pageCountStmt.getRow(pageCount);
pageCountStmt.reset();
return pageCount * m_pageSize;
}
}
bool OfflineStorage_SQLite::trimDbIfNeeded(size_t justAddedBytes)
{

Просмотреть файл

@ -39,7 +39,7 @@ namespace ARIASDK_NS_BEGIN {
virtual void ReleaseRecords(std::vector<StorageRecordId> const& ids, bool incrementRetryCount, HttpHeaders headers, bool& fromMemory) override;
virtual bool StoreSetting(std::string const& name, std::string const& value) override;
virtual std::string GetSetting(std::string const& name) override;
virtual unsigned GetSize() override;
virtual size_t GetSize() override;
virtual std::vector<StorageRecord>* GetRecords(bool shutdown, EventLatency minLatency = EventLatency_Normal, unsigned maxCount = 0) override;
virtual bool ResizeDb() override;

Просмотреть файл

@ -46,6 +46,12 @@ namespace ARIASDK_NS_BEGIN {
IOfflineStorage & m_offlineStorage;
public:
size_t GetSize()
{
return m_offlineStorage.GetSize();
}
RoutePassThrough<StorageObserver> start{ this, &StorageObserver::handleStart };
RoutePassThrough<StorageObserver> stop{ this, &StorageObserver::handleStop };

Просмотреть файл

@ -49,13 +49,16 @@ namespace ARIASDK_NS_BEGIN {
bool result = true;
int64_t stopTimes[5] = { 0, 0, 0, 0, 0 };
if (timeoutInSec > 0)
// Perform upload only if not paused
if ((timeoutInSec > 0) && (!tpm.isPaused()))
{
upload();
// perform uploads if required
stopTimes[0] = GetUptimeMs();
LOG_TRACE("Shutdown timer started...");
upload();
while (tpm.isUploadInProgress())
// try to push thru as much data as possible
while (storage.GetSize())
{
auto uploadTime = GetUptimeMs() - stopTimes[0];
if (uploadTime >= (1000L * timeoutInSec))

Просмотреть файл

@ -154,6 +154,11 @@ namespace ARIASDK_NS_BEGIN {
return (uploadCount() > 0) || m_isUploadScheduled;
}
virtual bool isPaused()
{
return m_isPaused;
}
};