Skip to content

Commit

Permalink
Merge branch 'bareos-16.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
joergsteffens committed Dec 2, 2016
2 parents ddc98d4 + 6a74d1b commit 35c25dd
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 45 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
9 changes: 7 additions & 2 deletions src/cats/bvfs.c
Expand Up @@ -323,9 +323,12 @@ static bool update_path_hierarchy_cache(JCR *jcr,
Mmsg(mdb->cmd, "UPDATE Job SET HasCache=-1 WHERE JobId=%s", jobid);
UPDATE_DB(jcr, mdb, mdb->cmd);

/* need to COMMIT here and start a new transaction */
/* need to COMMIT here to ensure that other concurrent .bvfs_update runs
* see the current HasCache value. A new transaction must only be started
* after having finished PathHierarchy processing, otherwise prevention
* from duplicate key violations in build_path_hierarchy() will not work.
*/
db_end_transaction(jcr, mdb);
db_start_transaction(jcr, mdb);

/* Inserting path records for JobId */
Mmsg(mdb->cmd, "INSERT INTO PathVisibility (PathId, JobId) "
Expand Down Expand Up @@ -387,6 +390,8 @@ static bool update_path_hierarchy_cache(JCR *jcr,
free(result);
}

db_start_transaction(jcr, mdb);

if (mdb->db_get_type_index() == SQL_TYPE_SQLITE3) {
Mmsg(mdb->cmd,
"INSERT INTO PathVisibility (PathId, JobId) "
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
98 changes: 57 additions & 41 deletions src/dird/quota.c
Expand Up @@ -196,60 +196,76 @@ 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;
}
}
}
}
}
} else if (jcr->res.client->GraceTime != 0) {
/*
* Reset softquota
*/
CLIENT_DBR cr;
memset(&cr, 0, sizeof(cr));
cr.ClientId = jcr->jr.ClientId;
if (!db_reset_quota_record(jcr, jcr->db, &cr)) {
Jmsg(jcr, M_WARNING, 0, _("Error setting Quota gracetime: ERR=%s\n"),
db_strerror(jcr->db));
} else {
jcr->res.client->GraceTime = 0;
Jmsg(jcr, M_INFO, 0, _("Soft Quota reset, Grace Period ends now.\n"));
}
}

bail_out:
Expand Down

0 comments on commit 35c25dd

Please sign in to comment.