Skip to content

Commit

Permalink
core: inherit class db_list_ctx from BStringList
Browse files Browse the repository at this point in the history
This change improves the handling of output from the "delete" command.
The changes are required to access the individual jobids in the list,
instead of having only access to the a string containing the comma seperated list of jobids.

The count() function has been replaced with the standard size() function.
The reset() function has been replaced with the standard clear() function.

cleanup

cleanup
  • Loading branch information
joergsteffens committed Sep 24, 2020
1 parent 658e604 commit 5d4cefe
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 139 deletions.
9 changes: 5 additions & 4 deletions core/src/cats/bvfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2009-2010 Free Software Foundation Europe e.V.
Copyright (C) 2016-2016 Planets Communications B.V.
Copyright (C) 2016-2019 Bareos GmbH & Co. KG
Copyright (C) 2016-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -336,7 +336,7 @@ void BareosDb::BvfsUpdateCache(JobControlRecord* jcr)
"ORDER BY JobId");
SqlQuery(cmd, DbListHandler, &jobids_list);

BvfsUpdatePathHierarchyCache(jcr, jobids_list.list);
BvfsUpdatePathHierarchyCache(jcr, jobids_list.list());

StartTransaction(jcr);
Dmsg0(dbglevel, "Cleaning pathvisibility\n");
Expand All @@ -354,9 +354,10 @@ void BareosDb::BvfsUpdateCache(JobControlRecord* jcr)
/*
* Update the bvfs cache for given jobids (1,2,3,4)
*/
bool BareosDb::BvfsUpdatePathHierarchyCache(JobControlRecord* jcr, char* jobids)
bool BareosDb::BvfsUpdatePathHierarchyCache(JobControlRecord* jcr,
const char* jobids)
{
char* p;
const char* p;
int status;
JobId_t JobId;
bool retval = true;
Expand Down
6 changes: 1 addition & 5 deletions core/src/cats/cats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2011-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -38,10 +38,6 @@
#include "bdb_query_names.inc"
#include "lib/berrno.h"


const std::vector<std::string>& db_list_ctx::get_items() const { return item_; }


bool BareosDb::MatchDatabase(const char* db_driver,
const char* db_name,
const char* db_address,
Expand Down
56 changes: 14 additions & 42 deletions core/src/cats/cats.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "include/bareos.h"
#include "cats/column_data.h"
#include "lib/bstringlist.h"
#include "lib/output_formatter.h"

#include <string>
Expand Down Expand Up @@ -491,50 +492,21 @@ class db_int64_ctx {
* Call back context for getting a list of comma separated strings from the
* database
*/
class db_list_ctx {
class db_list_ctx : public BStringList {
public:
POOLMEM* list = nullptr; /* list */
int count = 0; /* number of values seen */
void add(const db_list_ctx& list) { Append(list); }
void add(const char* str) { Append(str); }
void add(JobId_t id) { push_back(std::to_string(id)); }

db_list_ctx()
std::string get_as_string() const { return Join(','); }
const char* list()
{
list = GetPoolMemory(PM_FNAME);
reset();
}
~db_list_ctx()
{
FreePoolMemory(list);
list = NULL;
}
void reset()
{
*list = 0;
count = 0;
}
void add(const db_list_ctx& str)
{
if (str.count > 0) {
if (*list) { PmStrcat(list, ","); }
PmStrcat(list, str.list);
count += str.count;
const std::vector<std::string>& str_items = str.get_items();
item_.insert(std::end(item_), std::begin(str_items), std::end(str_items));
}
}
void add(const char* str)
{
if (count > 0) { PmStrcat(list, ","); }
PmStrcat(list, str);
count++;
item_.push_back(std::string(str));
strlist_ = get_as_string();
return strlist_.c_str();
}

const std::vector<std::string>& get_items() const;

private:
std::vector<std::string> item_;
db_list_ctx(const db_list_ctx&); /**< prohibit pass by value */
db_list_ctx& operator=(const db_list_ctx&); /**< prohibit class assignment */
std::string strlist_{};
};

typedef enum
Expand Down Expand Up @@ -687,7 +659,7 @@ class BareosDb : public BareosDbQueryEnum {
}

/* bvfs.c */
bool BvfsUpdatePathHierarchyCache(JobControlRecord* jcr, char* jobids);
bool BvfsUpdatePathHierarchyCache(JobControlRecord* jcr, const char* jobids);
void BvfsUpdateCache(JobControlRecord* jcr);
int BvfsLsDirs(PoolMem& query, void* ctx);
int BvfsBuildLsFileQuery(PoolMem& query,
Expand Down Expand Up @@ -746,7 +718,7 @@ class BareosDb : public BareosDbQueryEnum {
bool CreateBaseFileAttributesRecord(JobControlRecord* jcr,
AttributesDbRecord* ar);
bool CommitBaseFileAttributesRecord(JobControlRecord* jcr);
bool CreateBaseFileList(JobControlRecord* jcr, char* jobids);
bool CreateBaseFileList(JobControlRecord* jcr, const char* jobids);
bool CreateQuotaRecord(JobControlRecord* jcr, ClientDbRecord* cr);
bool CreateNdmpLevelMapping(JobControlRecord* jcr,
JobDbRecord* jr,
Expand Down Expand Up @@ -843,7 +815,7 @@ class BareosDb : public BareosDbQueryEnum {
bool GetCounterRecord(JobControlRecord* jcr, CounterDbRecord* cr);
bool GetQueryDbids(JobControlRecord* jcr, PoolMem& query, dbid_list& ids);
bool GetFileList(JobControlRecord* jcr,
char* jobids,
const char* jobids,
bool use_md5,
bool use_delta,
DB_RESULT_HANDLER* ResultHandler,
Expand All @@ -853,7 +825,7 @@ class BareosDb : public BareosDbQueryEnum {
JobDbRecord* jr,
db_list_ctx* jobids);
bool GetUsedBaseJobids(JobControlRecord* jcr,
POOLMEM* jobids,
const char* jobids,
db_list_ctx* result);
bool GetQuotaRecord(JobControlRecord* jcr, ClientDbRecord* cr);
bool get_quota_jobbytes(JobControlRecord* jcr,
Expand Down
4 changes: 2 additions & 2 deletions core/src/cats/sql_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -1139,7 +1139,7 @@ bool BareosDb::CommitBaseFileAttributesRecord(JobControlRecord* jcr)
* Returns: false on failure
* true on success
*/
bool BareosDb::CreateBaseFileList(JobControlRecord* jcr, char* jobids)
bool BareosDb::CreateBaseFileList(JobControlRecord* jcr, const char* jobids)
{
bool retval = false;
PoolMem buf(PM_MESSAGE);
Expand Down
10 changes: 5 additions & 5 deletions core/src/cats/sql_get.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -1250,7 +1250,7 @@ static void strip_md5(char* q)
* TODO: See if we can do the SORT only if needed (as an argument)
*/
bool BareosDb::GetFileList(JobControlRecord* jcr,
char* jobids,
const char* jobids,
bool use_md5,
bool use_delta,
DB_RESULT_HANDLER* ResultHandler,
Expand Down Expand Up @@ -1300,7 +1300,7 @@ bool BareosDb::GetFileList(JobControlRecord* jcr,
* This procedure gets the base jobid list used by jobids,
*/
bool BareosDb::GetUsedBaseJobids(JobControlRecord* jcr,
POOLMEM* jobids,
const char* jobids,
db_list_ctx* result)
{
PoolMem query(PM_MESSAGE);
Expand Down Expand Up @@ -1341,7 +1341,7 @@ bool BareosDb::AccurateGetJobids(JobControlRecord* jcr,
utime_t StartTime = (jr->StartTime) ? jr->StartTime : time(NULL);

bstrutime(date, sizeof(date), StartTime + 1);
jobids->reset();
jobids->clear();

/*
* First, find the last good Full backup for this job/client/fileset
Expand Down Expand Up @@ -1409,7 +1409,7 @@ bool BareosDb::AccurateGetJobids(JobControlRecord* jcr,
Mmsg(query, "SELECT JobId FROM btemp3%s ORDER by JobTDate", jobid);
}
SqlQueryWithHandler(query.c_str(), DbListHandler, jobids);
Dmsg1(1, "db_accurate_get_jobids=%s\n", jobids->list);
Dmsg1(1, "db_accurate_get_jobids=%s\n", jobids->list());
retval = true;

bail_out:
Expand Down
31 changes: 13 additions & 18 deletions core/src/dird/backup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2012 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2019 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -190,7 +190,6 @@ static bool GetBaseJobids(JobControlRecord* jcr, db_list_ctx* jobids)
JobDbRecord jr;
JobResource* job = nullptr;
JobId_t id;
char str_jobid[50];

if (!jcr->impl->res.job->base) {
return false; /* no base job, stop accurate */
Expand All @@ -202,14 +201,10 @@ static bool GetBaseJobids(JobControlRecord* jcr, db_list_ctx* jobids)
bstrncpy(jr.Name, job->resource_name_, sizeof(jr.Name));
jcr->db->GetBaseJobid(jcr, &jr, &id);

if (id) {
if (jobids->count) { PmStrcat(jobids->list, ","); }
PmStrcat(jobids->list, edit_uint64(id, str_jobid));
jobids->count++;
}
if (id) { jobids->add(id); }
}

return jobids->count > 0;
return (!jobids->empty());
}

/*
Expand Down Expand Up @@ -323,7 +318,7 @@ bool SendAccurateCurrentFiles(JobControlRecord* jcr)
*/
if (GetBaseJobids(jcr, &jobids)) {
jcr->HasBase = true;
Jmsg(jcr, M_INFO, 0, _("Using BaseJobId(s): %s\n"), jobids.list);
Jmsg(jcr, M_INFO, 0, _("Using BaseJobId(s): %s\n"), jobids.list());
} else {
return true;
}
Expand All @@ -336,7 +331,7 @@ bool SendAccurateCurrentFiles(JobControlRecord* jcr)
/*
* We are in Incr/Diff, but no Full to build the accurate list...
*/
if (jobids.count == 0) {
if (jobids.empty()) {
Jmsg(jcr, M_FATAL, 0, _("Cannot find previous jobids.\n"));
return false; /* fail */
}
Expand All @@ -353,14 +348,14 @@ bool SendAccurateCurrentFiles(JobControlRecord* jcr)
/*
* To be able to allocate the right size for htable
*/
Mmsg(buf, "SELECT sum(JobFiles) FROM Job WHERE JobId IN (%s)", jobids.list);
Mmsg(buf, "SELECT sum(JobFiles) FROM Job WHERE JobId IN (%s)", jobids.list());
jcr->db->SqlQuery(buf.c_str(), DbListHandler, &nb);
Dmsg2(200, "jobids=%s nb=%s\n", jobids.list, nb.list);
jcr->file_bsock->fsend("accurate files=%s\n", nb.list);
Dmsg2(200, "jobids=%s nb=%s\n", jobids.list(), nb.list());
jcr->file_bsock->fsend("accurate files=%s\n", nb.list());

if (jcr->HasBase) {
jcr->nb_base_files = str_to_int64(nb.list);
if (!jcr->db->CreateBaseFileList(jcr, jobids.list)) {
jcr->nb_base_files = str_to_int64(nb.list());
if (!jcr->db->CreateBaseFileList(jcr, jobids.list())) {
Jmsg(jcr, M_FATAL, 0, "error in jcr->db->CreateBaseFileList:%s\n",
jcr->db->strerror());
return false;
Expand All @@ -377,9 +372,9 @@ bool SendAccurateCurrentFiles(JobControlRecord* jcr)
return false; /* Fail */
}

jcr->db_batch->GetFileList(jcr, jobids.list, jcr->impl->use_accurate_chksum,
false /* no delta */, AccurateListHandler,
(void*)jcr);
jcr->db_batch->GetFileList(
jcr, jobids.list(), jcr->impl->use_accurate_chksum,
false /* no delta */, AccurateListHandler, (void*)jcr);
}

jcr->file_bsock->signal(BNET_EOD);
Expand Down
6 changes: 3 additions & 3 deletions core/src/dird/bsr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2002-2010 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2016 Bareos GmbH & Co. KG
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -347,7 +347,7 @@ static void DisplayVolInfo(UaContext* ua, RestoreContext& rx, JobId_t JobId)
void DisplayBsrInfo(UaContext* ua, RestoreContext& rx)
{
int i;
char* p;
const char* p;
JobId_t JobId;

/*
Expand Down Expand Up @@ -482,7 +482,7 @@ uint32_t WriteBsr(UaContext* ua, RestoreContext& rx, std::string& buffer)
bool first = true;
uint32_t LastIndex = 0;
uint32_t total_count = 0;
char* p;
const char* p;
JobId_t JobId;
RestoreBootstrapRecord* bsr;

Expand Down
18 changes: 9 additions & 9 deletions core/src/dird/consolidate.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2016-2019 Bareos GmbH & Co. KG
Copyright (C) 2016-2020 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -156,8 +156,8 @@ bool DoConsolidate(JobControlRecord* jcr)
* First determine the number of total incrementals
*/
jcr->db->AccurateGetJobids(jcr, &jcr->impl->jr, &jobids_ctx);
incrementals_total = jobids_ctx.count - 1;
Dmsg1(10, "unlimited jobids list: %s.\n", jobids_ctx.list);
incrementals_total = jobids_ctx.size() - 1;
Dmsg1(10, "unlimited jobids list: %s.\n", jobids_ctx.list());

/*
* If we are doing always incremental, we need to limit the search to
Expand All @@ -180,7 +180,7 @@ bool DoConsolidate(JobControlRecord* jcr)
}

jcr->db->AccurateGetJobids(jcr, &jcr->impl->jr, &jobids_ctx);
Dmsg1(10, "consolidate candidates: %s.\n", jobids_ctx.list);
Dmsg1(10, "consolidate candidates: %s.\n", jobids_ctx.list());

/**
* Consolidation of zero or one job does not make sense, we leave it like
Expand All @@ -207,11 +207,11 @@ bool DoConsolidate(JobControlRecord* jcr)
Dmsg3(10, "total: %d, to_consolidate: %d, limit: %d.\n",
incrementals_total, max_incrementals_to_consolidate,
jcr->impl->jr.limit);
jobids_ctx.reset();
jobids_ctx.clear();
jcr->db->AccurateGetJobids(jcr, &jcr->impl->jr, &jobids_ctx);
incrementals_to_consolidate = jobids_ctx.count - 1;
Dmsg2(10, "%d consolidate ids after limit: %s.\n", jobids_ctx.count,
jobids_ctx.list);
incrementals_to_consolidate = jobids_ctx.size() - 1;
Dmsg2(10, "%d consolidate ids after limit: %s.\n", jobids_ctx.size(),
jobids_ctx.list());
if (incrementals_to_consolidate < 1) {
Jmsg(jcr, M_INFO, 0,
_("%s: After limited query: less incrementals than required, "
Expand All @@ -231,7 +231,7 @@ bool DoConsolidate(JobControlRecord* jcr)
jobids = NULL;
}

jobids = strdup(jobids_ctx.list);
jobids = strdup(jobids_ctx.list());
p = jobids;

/**
Expand Down

0 comments on commit 5d4cefe

Please sign in to comment.