rippled
NodeStoreScheduler.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/main/NodeStoreScheduler.h>
21 #include <cassert>
22 
23 namespace ripple {
24 
25 NodeStoreScheduler::NodeStoreScheduler(JobQueue& jobQueue) : jobQueue_(jobQueue)
26 {
27 }
28 
29 void
31 {
32  if (jobQueue_.isStopped())
33  return;
34 
35  if (!jobQueue_.addJob(jtWRITE, "NodeObject::store", [&task]() {
36  task.performScheduledTask();
37  }))
38  {
39  // Job not added, presumably because we're shutting down.
40  // Recover by executing the task synchronously.
41  task.performScheduledTask();
42  }
43 }
44 
45 void
47 {
48  if (jobQueue_.isStopped())
49  return;
50 
54  1,
55  report.elapsed);
56 }
57 
58 void
60 {
61  if (jobQueue_.isStopped())
62  return;
63 
65 }
66 
67 } // namespace ripple
ripple::NodeStoreScheduler::scheduleTask
void scheduleTask(NodeStore::Task &task) override
Schedules a task.
Definition: NodeStoreScheduler.cpp:30
ripple::NodeStoreScheduler::onFetch
void onFetch(NodeStore::FetchReport const &report) override
Reports completion of a fetch Allows the scheduler to monitor the node store's performance.
Definition: NodeStoreScheduler.cpp:46
ripple::NodeStoreScheduler::onBatchWrite
void onBatchWrite(NodeStore::BatchWriteReport const &report) override
Reports the completion of a batch write Allows the scheduler to monitor the node store's performance.
Definition: NodeStoreScheduler.cpp:59
ripple::jtNS_SYNC_READ
@ jtNS_SYNC_READ
Definition: Job.h:91
ripple::NodeStore::FetchReport
Contains information about a fetch operation.
Definition: ripple/nodestore/Scheduler.h:32
ripple::JobQueue::addJob
bool addJob(JobType type, std::string const &name, JobHandler &&jobHandler)
Adds a job to the JobQueue.
Definition: JobQueue.h:166
ripple::jtNS_WRITE
@ jtNS_WRITE
Definition: Job.h:93
ripple::jtWRITE
@ jtWRITE
Definition: Job.h:73
ripple::NodeStore::Task
Derived classes perform scheduled tasks.
Definition: Task.h:27
ripple::JobQueue::isStopped
bool isStopped() const
Definition: JobQueue.cpp:297
ripple::NodeStoreScheduler::NodeStoreScheduler
NodeStoreScheduler(JobQueue &jobQueue)
Definition: NodeStoreScheduler.cpp:25
ripple::NodeStore::BatchWriteReport
Contains information about a batch write operation.
Definition: ripple/nodestore/Scheduler.h:44
ripple::JobQueue
A pool of threads to perform work.
Definition: JobQueue.h:55
ripple::NodeStore::FetchType::async
@ async
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::NodeStore::Task::performScheduledTask
virtual void performScheduledTask()=0
Performs the task.
ripple::NodeStoreScheduler::jobQueue_
JobQueue & jobQueue_
Definition: NodeStoreScheduler.h:43
cassert
ripple::NodeStore::BatchWriteReport::writeCount
int writeCount
Definition: ripple/nodestore/Scheduler.h:49
ripple::NodeStore::BatchWriteReport::elapsed
std::chrono::milliseconds elapsed
Definition: ripple/nodestore/Scheduler.h:48
ripple::JobQueue::addLoadEvents
void addLoadEvents(JobType t, int count, std::chrono::milliseconds elapsed)
Add multiple load events.
Definition: JobQueue.cpp:177
ripple::NodeStore::FetchReport::elapsed
std::chrono::milliseconds elapsed
Definition: ripple/nodestore/Scheduler.h:38
ripple::jtNS_ASYNC_READ
@ jtNS_ASYNC_READ
Definition: Job.h:92
ripple::NodeStore::FetchReport::fetchType
const FetchType fetchType
Definition: ripple/nodestore/Scheduler.h:39