1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00
one/include/LogDBRequest.h

143 lines
3.6 KiB
C
Raw Normal View History

/* -------------------------------------------------------------------------- */
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
/* not use this file except in compliance with the License. You may obtain */
/* a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
/* See the License for the specific language governing permissions and */
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#ifndef LOG_DB_REQUEST_H_
#define LOG_DB_REQUEST_H_
#include <string>
#include <sstream>
#include "SyncRequest.h"
/**
* This class represents a log entry replication request. The replication request
* is synchronous: once it has been replicated in a majority of followers the
* client is notified (SqlDB::exec_wr() call) and DB updated.
*/
class LogDBRequest : public SyncRequest
{
public:
LogDBRequest(unsigned int i, unsigned int t, const std::ostringstream& o);
2017-04-21 23:32:30 +03:00
LogDBRequest(unsigned int i, unsigned int t, unsigned int pi,
unsigned int pt, const char * s);
virtual ~LogDBRequest(){};
/**
* This function decrements the number of remaining server to replicate
* this entry. If it reaches 0, the client is notified
* @return number of replicas for this log
*/
int replicated();
/* ---------------------------------------------------------------------- */
/* Class access methods */
/* ---------------------------------------------------------------------- */
unsigned int index()
{
return _index;
};
2017-04-21 23:32:30 +03:00
unsigned int prev_index()
{
return _prev_index;
};
unsigned int term()
{
return _term;
};
2017-04-21 23:32:30 +03:00
unsigned int prev_term()
{
return _prev_term;
};
const std::string& sql()
{
return _sql;
};
int replicas()
{
return _replicas;
}
int to_commit()
{
return _to_commit;
}
void to_commit(int c)
{
_to_commit = c;
}
2017-04-21 23:32:30 +03:00
/**
* Function to lock the request
*/
void lock()
{
pthread_mutex_lock(&mutex);
};
/**
* Function to unlock the request
*/
void unlock()
{
pthread_mutex_unlock(&mutex);
};
private:
pthread_mutex_t mutex;
/**
* Index for this log entry
*/
unsigned int _index;
2017-04-21 23:32:30 +03:00
unsigned int _prev_index;
/**
* Term where this log entry was generated
*/
unsigned int _term;
2017-04-21 23:32:30 +03:00
unsigned int _prev_term;
/**
* SQL command to exec in the DB to update (INSERT, REPLACE, DROP)
*/
std::string _sql;
/**
* Remaining number of servers that need to replicate this record to commit
* it. Initialized to ( Number_Servers - 1 ) / 2
*/
int _to_commit;
/**
* Total number of replicas for this entry
*/
int _replicas;
};
#endif /*LOG_DB_REQUEST_H_*/