This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/main by this push:
     new c80e93d4d57 Use smgr-interface provided create_ao function. (#1534)
c80e93d4d57 is described below

commit c80e93d4d57ad2a3f6ca0bd7c71d804eab08a9a3
Author: reshke <[email protected]>
AuthorDate: Sat Jan 17 01:47:39 2026 +0500

    Use smgr-interface provided create_ao function. (#1534)
    
    * Use smgr-interface provided create_ao function.
    
    Extensible SMGR is one of usefull Cloudberry features
    that allow to hijack storage execution flow from extension.
    smgrcreate_ao however does not follow this memo. Fix that.
    
    * Add assertion and comment
---
 src/backend/cdb/cdbappendonlystoragewrite.c |  2 +-
 src/backend/storage/smgr/smgr.c             | 12 ++++++++++--
 src/include/storage/smgr.h                  |  5 ++++-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/backend/cdb/cdbappendonlystoragewrite.c 
b/src/backend/cdb/cdbappendonlystoragewrite.c
index 6a17e1cdd0f..bce2d069346 100755
--- a/src/backend/cdb/cdbappendonlystoragewrite.c
+++ b/src/backend/cdb/cdbappendonlystoragewrite.c
@@ -271,7 +271,7 @@ 
AppendOnlyStorageWrite_TransactionCreateFile(AppendOnlyStorageWrite *storageWrit
        // WALREP_FIXME: Pass isRedo == true, so that you don't get an error if 
it
        // exists already. That's currently OK, but in the future, other things
        // might depend on the isRedo flag, like whether to WAL-log the 
creation.
-       smgrcreate_ao(*relFileNode, segmentFileNum, true);
+       smgrcreate_ao(storageWrite->smgrAO, *relFileNode, segmentFileNum, true);
 
        /*
         * Create a WAL record, so that the segfile is also created after crash 
or
diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c
index a64c7384853..96e531e0798 100644
--- a/src/backend/storage/smgr/smgr.c
+++ b/src/backend/storage/smgr/smgr.c
@@ -127,6 +127,7 @@ static File AORelOpenSegFileXlog(RelFileNode node, int32 
segmentFileNum, int fil
 static const f_smgr_ao smgrswao[] = {
        /* regular file */
        {
+               .smgr_create_ao = mdcreate_ao,
                .smgr_FileClose = FileClose,
                .smgr_FileDiskSize = FileDiskSize,
                .smgr_FileTruncate = FileTruncate,
@@ -492,9 +493,16 @@ smgrcreate(SMgrRelation reln, ForkNumber forknum, bool 
isRedo)
  *             already because we are in a WAL replay sequence.
  */
 void
-smgrcreate_ao(RelFileNodeBackend rnode, int32 segmentFileNum, bool isRedo)
+smgrcreate_ao(const struct f_smgr_ao *smgr,
+                               RelFileNodeBackend rnode,
+                               int32 segmentFileNum, bool isRedo)
 {
-       mdcreate_ao(rnode, segmentFileNum, isRedo);
+       /* If we get there, check that provided smgr structure is sane.
+        * First off all, outer Appendonly IO utilities should
+        * pass valid smgr. Also, in-kernel smgr interface implementation
+        * smgr_create_ao as mdcreate_ao, and extension should define its own. 
*/
+       Assert(smgr != NULL && smgr->smgr_create_ao != NULL);
+       smgr->smgr_create_ao(rnode, segmentFileNum, isRedo);
        if (file_create_hook)
                (*file_create_hook)(rnode);
 }
diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h
index e7db1a43d49..4e3685dc55d 100644
--- a/src/include/storage/smgr.h
+++ b/src/include/storage/smgr.h
@@ -155,6 +155,7 @@ typedef struct f_smgr
 } f_smgr;
 
 typedef struct f_smgr_ao {
+       void                    (*smgr_create_ao) (RelFileNodeBackend rnode, 
int32 segmentFileNum, bool isRedo);
        off_t                   (*smgr_FileDiskSize) (File file);
        void                    (*smgr_FileClose) (File file);
        int                             (*smgr_FileTruncate) (File file, int64 
offset, uint32 wait_event_info);
@@ -193,7 +194,9 @@ extern void smgrclose(SMgrRelation reln);
 extern void smgrcloseall(void);
 extern void smgrclosenode(RelFileNodeBackend rnode);
 extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
-extern void smgrcreate_ao(RelFileNodeBackend rnode, int32 segmentFileNum, bool 
isRedo);
+extern void smgrcreate_ao(const struct f_smgr_ao *smgr,
+                               RelFileNodeBackend rnode,
+                               int32 segmentFileNum, bool isRedo);
 extern void smgrdosyncall(SMgrRelation *rels, int nrels);
 extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
 extern void smgrextend(SMgrRelation reln, ForkNumber forknum,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to