Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a --poll-timer switch to keep the database "warm".
  • Loading branch information
Andersbakken committed Dec 14, 2016
1 parent 883d739 commit d3a10d2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2678,3 +2678,11 @@ void Project::removeSource(uint32_t fileId)
removeDependencies(fileId);
Path::rmdir(sourceFilePath(fileId));
}

void Project::poll()
{
const Server::Options &options = Server::instance()->options();
for (auto it : mDependencies) {
validate(it.first, options.options & Server::ValidateFileMaps ? Validate : StatOnly);
}
}
1 change: 1 addition & 0 deletions src/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class Project : public std::enable_shared_from_this<Project>
void includeCompletions(Flags<QueryMessage::Flag> flags, const std::shared_ptr<Connection> &conn, Source &&source) const;
size_t bytesWritten() const { return mBytesWritten; }
void destroy() { mSaveDirty = false; }
void poll();
enum VisitResult {
Stop,
Continue,
Expand Down
14 changes: 13 additions & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,17 @@ static const List<Path> sSystemIncludePaths = {

Server *Server::sInstance = 0;
Server::Server()
: mSuspended(false), mEnvironment(Rct::environment()), mExitCode(0), mLastFileId(0), mCompletionThread(0)
: mSuspended(false), mEnvironment(Rct::environment()), mPollTimer(-1), mExitCode(0), mLastFileId(0), mCompletionThread(0)
{
assert(!sInstance);
sInstance = this;
}

Server::~Server()
{
if (mPollTimer >= 0)
EventLoop::eventLoop()->unregisterTimer(mPollTimer);

if (mCompletionThread) {
mCompletionThread->stop();
mCompletionThread->join();
Expand Down Expand Up @@ -203,6 +206,15 @@ bool Server::init(const Options &options)
}
}
}

assert(mOptions.pollTimer >= 0);
if (mOptions.pollTimer) {
mPollTimer = EventLoop::eventLoop()->registerTimer([this](int) {
if (std::shared_ptr<Project> proj = mCurrentProject.lock()) {
proj->poll();
}
}, mOptions.pollTimer * 1000);
}
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Server
rpVisitFileTimeout(0), rpIndexDataMessageTimeout(0), rpConnectTimeout(0),
rpConnectAttempts(0), rpNiceValue(0), maxCrashCount(0),
completionCacheSize(0), testTimeout(60 * 1000 * 5),
maxFileMapScopeCacheSize(512), tcpPort(0)
maxFileMapScopeCacheSize(512), pollTimer(0), tcpPort(0)
{
}

Expand All @@ -102,7 +102,8 @@ class Server
size_t jobCount, headerErrorJobCount, maxIncludeCompletionDepth;
int rpVisitFileTimeout, rpIndexDataMessageTimeout,
rpConnectTimeout, rpConnectAttempts, rpNiceValue, maxCrashCount,
completionCacheSize, testTimeout, maxFileMapScopeCacheSize, errorLimit;
completionCacheSize, testTimeout, maxFileMapScopeCacheSize, errorLimit,
pollTimer;
uint16_t tcpPort;
List<String> defaultArguments, excludeFilters;
Set<String> blockedArguments;
Expand Down Expand Up @@ -210,7 +211,7 @@ class Server
SocketServer::SharedPtr mUnixServer, mTcpServer;
List<String> mEnvironment;

int mExitCode;
int mPollTimer, mExitCode;
uint32_t mLastFileId;
std::shared_ptr<JobScheduler> mJobScheduler;
CompletionThread *mCompletionThread;
Expand Down
8 changes: 8 additions & 0 deletions src/rdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ enum OptionType {
LogTimestamp,
LogFlushOption,
SandboxRoot,
PollTimer,
NoRealPath,
Noop
};
Expand Down Expand Up @@ -338,6 +339,7 @@ int main(int argc, char** argv)
{ LogTimestamp, "log-timestamp", 0, CommandLineParser::NoValue, "Add timestamp to logs." },
{ LogFlushOption, "log-flush", 0, CommandLineParser::NoValue, "Flush stderr/stdout after each log." },
{ SandboxRoot, "sandbox-root", 0, CommandLineParser::Required, "Create index using relative paths by stripping dir (enables copying of tag index db files without need to reindex)." },
{ PollTimer, "poll-timer", 0, CommandLineParser::Required, "Poll the database of the current project every <arg> seconds. " },
{ NoRealPath, "no-realpath", 0, CommandLineParser::NoValue, "Don't use realpath(3) for files" },
{ Noop, "config", 'c', CommandLineParser::Required, "Use this file (instead of ~/.rdmrc)." },
{ Noop, "no-rc", 'N', CommandLineParser::NoValue, "Don't load any rc files." }
Expand Down Expand Up @@ -420,6 +422,12 @@ int main(int argc, char** argv)
return { String::format<1024>("Invalid argument to -z %s", value.constData()), CommandLineParser::Parse_Error };
}
break; }
case PollTimer: {
serverOpts.pollTimer = atoi(value.constData());
if (serverOpts.pollTimer < 0) {
return { String::format<1024>("Invalid argument to --poll-timer %s", value.constData()), CommandLineParser::Parse_Error };
}
break; }
case CleanSlate: {
serverOpts.options |= Server::ClearProjects;
break; }
Expand Down

0 comments on commit d3a10d2

Please sign in to comment.