Skip to content

Commit

Permalink
Soft Quota: add soft quota check after job run
Browse files Browse the repository at this point in the history
Before, check_softquota has was called at the beginning of a backup job.
The result was that the Soft Quota Grace Time was not set
when the client soft quota has been exceeded, but when the next job for
this client started.

This does not meet the expectation when using soft quotas.

Now the job report after a backup job also better reflects the real quota
status.
  • Loading branch information
joergsteffens committed Dec 2, 2016
1 parent 5067c6e commit 6a74d1b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 44 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -88,6 +88,7 @@ Lorenz Schori
Luca Berra
Lucas B. Cohen
Lucas Di Pentima
Ludek Finstrle
Ludovic Strappazon
Lukas Nykryn
Maik Aussendorf
Expand Down
10 changes: 8 additions & 2 deletions src/dird/backup.c
Expand Up @@ -368,7 +368,7 @@ bool do_native_backup(JCR *jcr)

if (check_softquotas(jcr)) {
Dmsg0(10, "Quota exceeded\n");
Jmsg(jcr, M_FATAL, 0, _("Soft Quota Exceeded / Grace Time expired. Job terminated.\n"));
Jmsg(jcr, M_FATAL, 0, _("Soft Quota exceeded / Grace Time expired. Job terminated.\n"));
return false;
}

Expand Down Expand Up @@ -600,6 +600,12 @@ bool do_native_backup(JCR *jcr)
Jmsg(jcr, M_FATAL, 0, "%s", db_strerror(jcr->db));
}

/*
* Check softquotas after job did run.
* If quota is exceeded now, set the GraceTime.
*/
check_softquotas(jcr);

if (status == JS_Terminated) {
native_backup_cleanup(jcr, status);
return true;
Expand Down Expand Up @@ -1016,7 +1022,7 @@ void generate_backup_summary(JCR *jcr, CLIENT_DBR *cr, int msg_type, const char
bstrftimes(gdt, sizeof(gdt), jcr->res.client->GraceTime +
jcr->res.client->SoftQuotaGracePeriod);
} else {
bstrncpy(gdt, "Soft Quota was never exceeded", sizeof(gdt));
bstrncpy(gdt, "Soft Quota not exceeded", sizeof(gdt));
}
Mmsg(quota_info, _(
" Quota Used: %s (%sB)\n"
Expand Down
87 changes: 45 additions & 42 deletions src/dird/quota.c
Expand Up @@ -196,57 +196,59 @@ bool check_softquotas(JCR *jcr)
Dmsg2(dbglvl, "SoftQuota Grace Period for %s is %d\n", jcr->jr.Name, jcr->res.client->SoftQuotaGracePeriod);
Dmsg2(dbglvl, "SoftQuota Grace Time for %s is %d\n", jcr->jr.Name, jcr->res.client->GraceTime);

if (jcr->jr.JobSumTotalBytes > jcr->res.client->SoftQuota) {
if ((jcr->jr.JobSumTotalBytes + jcr->SDJobBytes) > jcr->res.client->SoftQuota) {
/*
* Only warn once about softquotas in the job
* Check if gracetime has been set
*/
if (jcr->res.client->GraceTime == 0 && jcr->res.client->SoftQuotaGracePeriod) {
Dmsg1(dbglvl, "update_quota_gracetime: %d\n", now);
if (!db_update_quota_gracetime(jcr, jcr->db, &jcr->jr)) {
Jmsg(jcr, M_WARNING, 0, _("Error setting Quota gracetime: ERR=%s"),
db_strerror(jcr->db));
} else {
Jmsg(jcr, M_ERROR, 0, _("Softquota Exceeded, Grace Period starts now.\n"));
}
jcr->res.client->GraceTime = now;
goto bail_out;
} else if (jcr->res.client->SoftQuotaGracePeriod &&
(now - (uint64_t)jcr->res.client->GraceTime) < (uint64_t)jcr->res.client->SoftQuotaGracePeriod) {
Jmsg(jcr, M_ERROR, 0, _("Softquota Exceeded, will be enforced after Grace Period expires.\n"));
} else if (jcr->res.client->SoftQuotaGracePeriod &&
(now - (uint64_t)jcr->res.client->GraceTime) > (uint64_t)jcr->res.client->SoftQuotaGracePeriod) {
/*
* If gracetime has expired update else check more if not set softlimit yet then set and bail out.
*/
if (jcr->res.client->QuotaLimit < 1) {
if (!db_update_quota_softlimit(jcr, jcr->db, &jcr->jr)) {
Jmsg(jcr, M_WARNING, 0, _("Error setting Quota Softlimit: ERR=%s"),
db_strerror(jcr->db));
}
Jmsg(jcr, M_WARNING, 0, _("Softquota Exceeded and Grace Period expired.\n"));
Jmsg(jcr, M_INFO, 0, _("Setting Burst Quota to %d Bytes.\n"),
jcr->jr.JobSumTotalBytes);
jcr->res.client->QuotaLimit = jcr->jr.JobSumTotalBytes;
retval = true;
goto bail_out;
} else {
if (jcr->res.client->SoftQuotaGracePeriod) {
if (jcr->res.client->GraceTime == 0) {
Dmsg1(dbglvl, "update_quota_gracetime: %d\n", now);
if (!db_update_quota_gracetime(jcr, jcr->db, &jcr->jr)) {
Jmsg(jcr, M_WARNING, 0, _("Error setting Quota gracetime: ERR=%s"),
db_strerror(jcr->db));
} else {
Jmsg(jcr, M_ERROR, 0, _("Soft Quota exceeded, Grace Period starts now.\n"));
}
jcr->res.client->GraceTime = now;
goto bail_out;
} else if ((now - (uint64_t)jcr->res.client->GraceTime) < (uint64_t)jcr->res.client->SoftQuotaGracePeriod) {
Jmsg(jcr, M_ERROR, 0, _("Soft Quota exceeded, will be enforced after Grace Period expires.\n"));
} else if ((now - (uint64_t)jcr->res.client->GraceTime) > (uint64_t)jcr->res.client->SoftQuotaGracePeriod) {
/*
* If we use strict quotas enforce the pure soft quota limit.
* If gracetime has expired update else check more if not set softlimit yet then set and bail out.
*/
if (jcr->res.client->StrictQuotas &&
jcr->jr.JobSumTotalBytes > jcr->res.client->SoftQuota) {
Dmsg0(dbglvl, "Softquota Exceeded, enforcing Strict Quota Limit.\n");
if (jcr->res.client->QuotaLimit < 1) {
if (!db_update_quota_softlimit(jcr, jcr->db, &jcr->jr)) {
Jmsg(jcr, M_WARNING, 0, _("Error setting Quota Softlimit: ERR=%s"),
db_strerror(jcr->db));
}
Jmsg(jcr, M_WARNING, 0, _("Soft Quota exceeded and Grace Period expired.\n"));
Jmsg(jcr, M_INFO, 0, _("Setting Burst Quota to %d Bytes.\n"),
jcr->jr.JobSumTotalBytes);
jcr->res.client->QuotaLimit = jcr->jr.JobSumTotalBytes;
retval = true;
goto bail_out;
} else if (!jcr->res.client->StrictQuotas &&
jcr->jr.JobSumTotalBytes >= jcr->res.client->QuotaLimit) {
} else {
/*
* If strict quotas turned off use the last known limit
* If we use strict quotas enforce the pure soft quota limit.
*/
Jmsg(jcr, M_WARNING, 0, _("Softquota Exceeded, enforcing Burst Quota Limit.\n"));
retval = true;
goto bail_out;
if (jcr->res.client->StrictQuotas) {
if (jcr->jr.JobSumTotalBytes > jcr->res.client->SoftQuota) {
Dmsg0(dbglvl, "Soft Quota exceeded, enforcing Strict Quota Limit.\n");
retval = true;
goto bail_out;
}
} else {
if (jcr->jr.JobSumTotalBytes >= jcr->res.client->QuotaLimit) {
/*
* If strict quotas turned off use the last known limit
*/
Jmsg(jcr, M_WARNING, 0, _("Soft Quota exceeded, enforcing Burst Quota Limit.\n"));
retval = true;
goto bail_out;
}
}
}
}
}
Expand All @@ -261,7 +263,8 @@ bool check_softquotas(JCR *jcr)
Jmsg(jcr, M_WARNING, 0, _("Error setting Quota gracetime: ERR=%s\n"),
db_strerror(jcr->db));
} else {
Jmsg(jcr, M_ERROR, 0, _("Softquota Reset, Grace Period ends now.\n"));
jcr->res.client->GraceTime = 0;
Jmsg(jcr, M_INFO, 0, _("Soft Quota reset, Grace Period ends now.\n"));
}
}

Expand Down

0 comments on commit 6a74d1b

Please sign in to comment.