OpenSDN source code
db_partition.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef ctrlplane_db_partition_h
7 #define ctrlplane_db_partition_h
8 
9 #include <boost/function.hpp>
10 
11 #include "base/util.h"
12 #include "db/db_table.h"
13 #include "db/db_table_partition.h"
14 
15 class DB;
16 class DBClient;
17 class DBTablePartBase;
18 
19 // Database shard interface.
20 // Each shard handles the full pipeline of DB update processing.
21 class DBPartition {
22 public:
23  typedef boost::function<void(void)> Callback;
24 
25  explicit DBPartition(DB *db, int partition_id);
26  ~DBPartition();
27 
28  // Enqueue a request at the start of the DB processing pipeline.
29  // Returns false if the client should stop enqueuing updates.
30  bool EnqueueRequest(DBTablePartBase *tpart, DBClient *client,
31  DBRequest *req);
32 
33  void EnqueueRemove(DBTablePartBase *tpart, DBEntryBase *db_entry);
34 
35  // Enqueue table on change list.
36  void OnTableChange(DBTablePartBase *tpart);
37  bool IsDBQueueEmpty() const;
38  void SetQueueDisable(bool disable);
39 
40  long request_queue_len() const;
41  uint64_t total_request_count() const;
42  uint64_t max_request_queue_len() const;
43  int task_id() const;
44 
45 private:
46  class WorkQueue;
47  class QueueRunner;
48 
49  DB *db_;
50  std::unique_ptr<WorkQueue> work_queue_;
52 
54 };
55 
56 #endif
DISALLOW_COPY_AND_ASSIGN(DBPartition)
long request_queue_len() const
uint64_t total_request_count() const
void EnqueueRemove(DBTablePartBase *tpart, DBEntryBase *db_entry)
void SetQueueDisable(bool disable)
DBPartition(DB *db, int partition_id)
uint64_t max_request_queue_len() const
bool EnqueueRequest(DBTablePartBase *tpart, DBClient *client, DBRequest *req)
int task_id() const
static int db_partition_task_id_
Definition: db_partition.h:51
std::unique_ptr< WorkQueue > work_queue_
Definition: db_partition.h:50
bool IsDBQueueEmpty() const
void OnTableChange(DBTablePartBase *tpart)
boost::function< void(void)> Callback
Definition: db_partition.h:23
Definition: db.h:25