Call attemptMergeAllCallback immediately after startup instead of after sleep of 5 minutes

This commit is contained in:
Ai Lin Chia
2016-07-11 17:08:16 +02:00
parent 244a856032
commit ccd899fae2
3 changed files with 13 additions and 19 deletions

@ -193,8 +193,9 @@ bool Loop::registerWriteCallback ( int fd, void *state, void (* callback)(int fd
}
// tick is in milliseconds
bool Loop::registerSleepCallback ( int32_t tick, void *state, void (* callback)(int fd,void *state ), int32_t niceness ) {
if ( ! addSlot ( true, MAX_NUM_FDS, state, callback , niceness ,tick) ) {
bool Loop::registerSleepCallback ( int32_t tick, void *state, void (* callback)(int fd,void *state ),
int32_t niceness, bool immediate ) {
if ( ! addSlot ( true, MAX_NUM_FDS, state, callback, niceness, tick, immediate ) ) {
log( LOG_WARN, "loop: Unable to register sleep callback" );
return false;
}
@ -207,10 +208,8 @@ bool Loop::registerSleepCallback ( int32_t tick, void *state, void (* callback)(
}
// . returns false and sets g_errno on error
bool Loop::addSlot ( bool forReading , int fd, void *state,
void (* callback)(int fd, void *state), int32_t niceness ,
int32_t tick ) {
bool Loop::addSlot ( bool forReading , int fd, void *state, void (* callback)(int fd, void *state),
int32_t niceness , int32_t tick, bool immediate ) {
// ensure fd is >= 0
if ( fd < 0 ) {
g_errno = EBADENGINEER;
@ -301,7 +300,7 @@ bool Loop::addSlot ( bool forReading , int fd, void *state,
s->m_tick = tick;
// the last called time
s->m_lastCall = gettimeofdayInMilliseconds();
s->m_lastCall = immediate ? 0 : gettimeofdayInMilliseconds();
// debug msg
//log("Loop::registered fd=%i state=%" PRIu32,fd,state);

11
Loop.h

@ -121,10 +121,8 @@ class Loop {
// . register this callback to be called every second
// . TODO: implement "seconds" parameter
bool registerSleepCallback ( int32_t milliseconds ,
void *state,
void (* callback)(int fd,void *state ) ,
int32_t niceness = 1 );
bool registerSleepCallback ( int32_t milliseconds, void *state, void (* callback)(int fd,void *state ),
int32_t niceness = 1, bool immediate = false );
// unregister call back for reading, writing or sleeping
void unregisterReadCallback ( int fd, void *state , void (* callback)(int fd,void *state), bool silent = false );
@ -173,9 +171,8 @@ class Loop {
bool silent , // = false );
bool forReading );
bool addSlot ( bool forReading , int fd , void *state ,
void (* callback)(int fd , void *state ) ,
int32_t niceness , int32_t tick = 0x7fffffff ) ;
bool addSlot ( bool forReading , int fd , void *state , void (* callback)(int fd , void *state ),
int32_t niceness , int32_t tick = 0x7fffffff, bool immediate = false ) ;
// set how long to pause waiting for singals (in milliseconds)
void setSigWaitTime ( int32_t ms ) ;

@ -2240,14 +2240,12 @@ int main2 ( int argc , char *argv[] ) {
return 0;
}
// . register a callback to try to merge everything every 2 seconds
// . register a callback to try to merge everything every 60 seconds
// . do not exit if we couldn't do this, not a huge deal
// . put this in here instead of Rdb.cpp because we don't want
// generator commands merging on us
// . the (void *)1 prevents gb from logging merge info every 2 seconds
// . put this in here instead of Rdb.cpp because we don't want generator commands merging on us
// . niceness is 1
// BR: Upped from 2 sec to 60. No need to check for merge every 2 seconds.
if ( !g_loop.registerSleepCallback( 60000, (void *)1, attemptMergeAllCallback, 1) ) {
if ( !g_loop.registerSleepCallback( 60000, (void *)1, attemptMergeAllCallback, 1, true ) ) {
log( LOG_WARN, "db: Failed to init merge sleep callback." );
}