Skip to content

Commit

Permalink
Improve recovery on Hibernate error and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianM27 committed May 15, 2024
1 parent e9026f3 commit 4bab06d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
13 changes: 9 additions & 4 deletions daemon/lib/source/DobbyHibernate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ typedef enum {
typedef enum {
MEMCR_OK = 0,
MEMCR_ERROR = -1,
MEMCR_INVALID_PID = -2
MEMCR_INVALID_PID = -2,
MEMCR_SOCKET_READ_ERROR = -3
} ServerResponseCode;

typedef struct {
Expand Down Expand Up @@ -142,7 +143,6 @@ static bool SendRcvCmd(const ServerRequest* cmd, ServerResponse* resp, uint32_t
AI_LOG_FN_ENTRY();
int cd;
int ret;
struct sockaddr_in addr = { 0 };
resp->respCode = MEMCR_ERROR;

cd = Connect(serverLocator, timeoutMs);
Expand All @@ -154,15 +154,16 @@ static bool SendRcvCmd(const ServerRequest* cmd, ServerResponse* resp, uint32_t

ret = write(cd, cmd, sizeof(ServerRequest));
if (ret != sizeof(ServerRequest)) {
AI_LOG_ERROR("Socket write failed: ret %d", ret);
AI_LOG_ERROR("Socket write failed: ret %d, %m", ret);
close(cd);
AI_LOG_FN_EXIT();
return false;
}

ret = read(cd, resp, sizeof(ServerResponse));
if (ret != sizeof(ServerResponse)) {
AI_LOG_ERROR("Socket read failed: ret %d", ret);
AI_LOG_ERROR("Socket read failed: ret %d, %m", ret);
resp->respCode = MEMCR_SOCKET_READ_ERROR;
close(cd);
AI_LOG_FN_EXIT();
return false;
Expand All @@ -188,6 +189,10 @@ DobbyHibernate::Error DobbyHibernate::HibernateProcess(const pid_t pid, const ui
AI_LOG_INFO("Hibernate process PID %d success", pid);
AI_LOG_FN_EXIT();
return DobbyHibernate::Error::ErrorNone;
} else if (resp.respCode == MEMCR_SOCKET_READ_ERROR) {
AI_LOG_WARN("Error Hibernate timeout process PID %d ret %d", pid, resp.respCode);
AI_LOG_FN_EXIT();
return DobbyHibernate::Error::ErrorTimeout;
} else {
AI_LOG_WARN("Error Hibernate process PID %d ret %d", pid, resp.respCode);
AI_LOG_FN_EXIT();
Expand Down
3 changes: 2 additions & 1 deletion daemon/lib/source/DobbyHibernate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class DobbyHibernate
enum Error
{
ErrorNone = 0,
ErrorGeneral = 1
ErrorGeneral = 1,
ErrorTimeout = 2
};

enum CompressionAlg
Expand Down
31 changes: 2 additions & 29 deletions daemon/lib/source/DobbyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1566,35 +1566,7 @@ bool DobbyManager::hibernateContainer(int32_t cd, const std::string& options)
std::thread hibernateThread =
std::thread([=]()
{
//TODO: --delay support is temporary and should be removed
int delayMs = 0;
size_t delayMsPos = options.find("--delay=");
if (delayMsPos != std::string::npos)
{
delayMs = std::stoi(&options[delayMsPos + std::string("--delay=").length()], nullptr, 10);
}
DobbyHibernate::Error ret = DobbyHibernate::Error::ErrorNone;

int delayChunkMs = 100;
while (delayMs > 0)
{
int sleepTime = delayMs > delayChunkMs? delayChunkMs : delayMs;
delayMs -= sleepTime;
std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
{
std::lock_guard<std::mutex> locker(mLock);
if (mContainers.find(id) == mContainers.end() ||
mContainers[id]->descriptor != cd ||
mContainers[id]->state != DobbyContainer::State::Hibernating)
{
AI_LOG_WARN("Hibernation of: %s with descriptor %d aborted", id.c_str(), cd);
AI_LOG_FN_EXIT();
return;
}
}
}
//TODO: --delay support end

// create a stats object for the container to get list of PIDs
std::unique_lock<std::mutex> locker(mLock);
DobbyStats stats(it->first, mEnvironment, mUtilities);
Expand All @@ -1619,7 +1591,8 @@ bool DobbyManager::hibernateContainer(int32_t cd, const std::string& options)
if (ret != DobbyHibernate::Error::ErrorNone)
{
AI_LOG_WARN("Error hibernating pid: '%d'", pid);
// revert previous Hibernations and break
// try to revert current and previous Hibernations and break
DobbyHibernate::WakeupProcess(pid);
while (pidIt != jsonPids.begin())
{
--pidIt;
Expand Down

0 comments on commit 4bab06d

Please sign in to comment.