]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Optimize Aligned format for Single Item Restore
authorEric Bollengier <eric@baculasystems.com>
Fri, 17 Jun 2022 08:56:20 +0000 (10:56 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:58 +0000 (13:56 +0200)
Allow to read only the ameta records and rehydrate the data block
only when needed.

dev->clear_rehydrate_record();
...
// read blocks
dev->rehydrate_record(dcr, rec)

bacula/src/stored/aligned_dev.h
bacula/src/stored/butil.c
bacula/src/stored/dev.h
bacula/src/stored/record.h
bacula/src/stored/record_read.c

index b3c9ebeb0bcc21aecb4dbeab4c6a1b4e259bfdb4..1f016617c777b8f774227c1f71a84e8c3da5f934 100644 (file)
@@ -102,9 +102,9 @@ public:
    void select_data_stream(DCR *dcr, DEV_RECORD *rec);
    bool flush_block(DCR *dcr);
    bool do_pre_write_checks(DCR *dcr, DEV_RECORD *rec);
-
-
-
+   bool get_os_device_freespace();
+   bool is_fs_nearly_full(uint64_t threshold);
+   int rehydrate_record(DCR *dcr, DEV_RECORD *rec);
    /*
     * Locking and blocking calls
     */
index 9aa95cf131c5c888b1d2bd1d911b810dfd19df21..34403ab42d0a0641cb2d9a51bf415db2d7b8b170 100644 (file)
@@ -197,6 +197,9 @@ static DCR *setup_to_access_device(JCR *jcr, char *dev_name,
       if (read_dedup_data) {
          Dmsg0(DT_DEDUP|215, "Initialize dedup interface\n");
          jcr->read_dcr->dev->setup_dedup_rehydration_interface(jcr->read_dcr);
+
+      } else {
+         dev->set_delay_adata(); /* Do not read aligned data */
       }
    } else {
       if (!first_open_device(dcr)) {
index ed45758a309590308d745071a5fcf8084638a2c0..54eaf9f1998d3aee878990dcfd3e9ef655dad9c1 100644 (file)
@@ -299,6 +299,7 @@ public:
    bool m_shstore_user_lock;          /* set if user set shared lock */
    bool m_shstore_register;           /* set if register key set */
    bool m_shstore_blocked;            /* Set if I am blocked */
+   bool m_delay_adata;                /* Set if we need to ask to read adata */
    bool adata;                        /* set if adata device */
    int label_type;                    /* Bacula/ANSI/IBM label types */
    uint32_t drive_index;              /* Autochanger drive index (base 0) */
@@ -464,6 +465,8 @@ public:
    void set_load() { m_load = true; };
    void set_wait() { m_wait = true; };
    void clear_wait() { m_wait = false; };
+   void set_delay_adata() { m_delay_adata = true;};
+   void clear_delay_adata() { m_delay_adata = false;};
    bool must_wait() const { return m_wait; };
    void inc_reserved() { m_num_reserved++; }
    void set_mounted(int val) { if (val) state |= ST_MOUNTED; \
@@ -527,8 +530,6 @@ public:
 
 
    /* Virtual functions that can be overridden */
-   virtual void set_file_size(uint64_t val) { file_size = val;};
-   virtual uint64_t update_file_size(uint64_t add) { file_size += add; return file_size; };
    virtual void setVolCatName(const char *name);
    virtual void setVolCatStatus(const char *status);
    virtual void free_dcr_blocks(DCR *dcr);        /* in block_util.c */
@@ -708,6 +709,7 @@ public:
    void open_tape_device(DCR *dcr, int omode);   /* in dev.c */
    void open_file_device(DCR *dcr, int omode);   /* in dev.c */
 
+   virtual int rehydrate_record(DCR *dcr, DEV_RECORD *rec) { return 1;};
    virtual bool setup_dedup_rehydration_interface(DCR *dcr) { return false; };
    virtual void free_dedup_rehydration_interface(DCR *dcr) { };
    virtual GetMsg *get_msg_queue(JCR *jcr, BSOCK *sock, int32_t bufsize)
@@ -811,6 +813,7 @@ public:
    int Copy;                          /* identical copy number */
    int Stripe;                        /* RAIT stripe */
    VOLUME_CAT_INFO VolCatInfo;        /* Catalog info for desired volume */
+   /* *** BEEF *** */
    uint32_t crc32(unsigned char *buf, int len, uint32_t expected_crc);
 
    /* *** SIR *** */
index 196849d60622229525bbefb31d21279052c3242d..4f87de3bba95cf54d487933d1f78c9d7be9f2bae 100644 (file)
@@ -52,7 +52,8 @@ enum rec_state {
    st_cont_adata_rechdr,                  /* 6 Adata continuation rechdr */
    st_adata,                              /* 7 Write aligned data */
    st_cont_adata,                         /* 8 Write more aligned data */
-   st_adata_label                         /* 9 Writing adata vol label */
+   st_adata_label,                        /* 9 Writing adata vol label */
+   st_header_only                         /* 10 Read only the header (aligned) */
 };
 
 
index f39f21dfb77846bd8e1ef955e36bba4c50a3946e..8b728758ad9d5292e4835e660c752a50994fe59d 100644 (file)
@@ -31,7 +31,7 @@
 
 /* Imported subroutines */
 static const int read_dbglvl = 200|DT_VOLUME;
-static const int dbgep = 400|DT_VOLUME;         /* debug execution path */
+static const int dbgep = 200|DT_VOLUME;         /* debug execution path */
 
 /*
  * Read the header record
@@ -86,6 +86,7 @@ static bool read_header(DCR *dcr, DEV_BLOCK *block, DEV_RECORD *rec)
       if (dcr->dev->have_adata_header(dcr, rec, FileIndex, Stream, VolSessionId)) {
          return true;
       }
+
       block->bufp += rhl;
       block->binbuf -= rhl;
       rec->remlen -= rhl;
@@ -237,13 +238,6 @@ bool read_record_from_block(DCR *dcr,  DEV_RECORD *rec)
 
    Dmsg0(dbgep, "=== rpath 1 Enter read_record_from block\n");
 
-   /* We return from a previous call with aligned volume, we did not read
-    * the data on disk, let's read the next ameta record.
-    */
-   if (rec->rstate == st_header_only) {
-      rec->remainder = 0;
-      rec->rstate = st_header;
-   }
    /* Update the Record number only if we have a new record */
    if (rec->remainder == 0) {
       rec->RecNum = dcr->block->RecNum;
@@ -253,7 +247,7 @@ bool read_record_from_block(DCR *dcr,  DEV_RECORD *rec)
 
    /* We read the next record */
    dcr->block->RecNum++;
-   
+
    for ( ;; ) {
       switch (rec->rstate) {
       case st_none:
@@ -271,10 +265,8 @@ bool read_record_from_block(DCR *dcr,  DEV_RECORD *rec)
          continue;
 
       case st_header_only:
-         /* We come from the st_cont_adata_rechdr state and we may read
-          * or not the data associated
-          */
          Dmsg0(dbgep, "=== rpath 37 st_header_only\n");
+         rec->rstate = st_header;
          goto get_out;
 
       case st_data: