@@ -6024,6 +6024,35 @@ static inline int is_write_request(int type)
60246024
60256025void free_cached_idx (uint8_t * * cached_idx );
60266026
6027+ int dbtable_get_highest_genid (struct dbtable * table , unsigned long long * genids )
6028+ {
6029+ int rc ;
6030+ void * rec ;
6031+ int i ;
6032+ int orglen = MAXLRL ;
6033+ int bdberr ;
6034+
6035+ rec = alloca (orglen );
6036+
6037+ /* get max genid for each stripe */
6038+ for (i = 0 ; i < table -> dtastripe ; ++ i ) {
6039+ uint8_t ver ;
6040+ int dtalen = orglen ;
6041+
6042+ rc = bdb_find_newest_genid (table -> handle , NULL , i , rec , & dtalen , dtalen , & genids [i ], & ver , & bdberr );
6043+ if (rc == IX_FND )
6044+ logmsg (LOGMSG_INFO , "%s: LOOKING FOR %s STRIPE %d found genid %llx (%lld)\n" , __func__ , table -> tablename , i ,
6045+ genids [i ], genids [i ]);
6046+ else if (rc == 1 )
6047+ logmsg (LOGMSG_INFO , "%s: LOOKING FOR %s STRIPE %d empty stripe, genid will be 0\n" , __func__ ,
6048+ table -> tablename , i );
6049+ else if (rc < 0 || bdberr != BDBERR_NOERROR ) {
6050+ return -1 ;
6051+ }
6052+ }
6053+ return 0 ;
6054+ }
6055+
60276056int gbl_disable_tpsc_tblvers = 0 ;
60286057static int start_schema_change_tran_wrapper (const char * tblname ,
60296058 timepart_view_t * * pview ,
@@ -6116,8 +6145,18 @@ static int start_schema_change_tran_wrapper(const char *tblname,
61166145 rc = populate_db_with_alt_schema (thedb , sc -> newdb , sc -> newcsc2 , & err );
61176146 if (rc ) {
61186147 logmsg (LOGMSG_ERROR , "%s: populate_db_with_alt_schema failed with rc %d %s\n" , __func__ , rc , err .errstr );
6148+ sc_errf (sc , "%s: populate_db_with_alt_schema failed with rc %d %s\n" , __func__ , rc , err .errstr );
61196149 return VIEW_ERR_SC ;
61206150 }
6151+
6152+ /* we also need to retrieve the highest genid */
6153+ if (arg -> indx > 0 ) {
6154+ rc = dbtable_get_highest_genid (sc -> newdb , arg -> retros -> cs [arg -> indx - 1 ].resume_genids );
6155+ if (rc ) {
6156+ sc_errf (sc , "%s: failed to find newest genid for shard %s\n" , __func__ , sc -> tablename );
6157+ return VIEW_ERR_SC ;
6158+ }
6159+ }
61216160 }
61226161
61236162 if (arg -> lockless ) {
@@ -6352,6 +6391,7 @@ static int _process_partitioning_retro(timepart_sc_arg_t *arg)
63526391 struct schema_change_type * sc = arg -> s ;
63536392 struct errstat err = {0 };
63546393 int rc = 0 ;
6394+ int ii ;
63556395
63566396 /* determine retroactive time boundaries for the shards */
63576397 int len = sizeof (struct timepart_retro ) +
@@ -6370,7 +6410,7 @@ static int _process_partitioning_retro(timepart_sc_arg_t *arg)
63706410 sc -> partition .u .tpt .retention * sizeof (int ));
63716411 retros -> cs = (timepart_retro_ctr_t * )((char * )retros + sizeof (struct timepart_retro ) +
63726412 sc -> partition .u .tpt .retention * (sizeof (int ) + sizeof (int * )));
6373- for (int ii = 0 ; ii < sc -> partition .u .tpt .retention ; ii ++ ) {
6413+ for (ii = 0 ; ii < sc -> partition .u .tpt .retention ; ii ++ ) {
63746414 pthread_mutex_init (& retros -> cs [ii ].mtx , 0 );
63756415 }
63766416 rc = timepart_populate_timelimits (sc -> newpartition , retros , & err );
@@ -6405,6 +6445,20 @@ static int _process_partitioning_retro(timepart_sc_arg_t *arg)
64056445 }
64066446 retros -> ss [sc -> partition .u .tpt .retention - 1 ] = arg -> s ;
64076447
6448+ /* set the maximum genid for each stripe */
6449+ for (int stripe = 0 ; stripe < sc -> newdb -> dtastripe ; stripe ++ ) {
6450+ for (ii = 0 ; ii < sc -> partition .u .tpt .retention ; ii ++ ) {
6451+ unsigned long long genid = retros -> cs [ii ].resume_genids [stripe ];
6452+ if (genid > retros -> resume_genids [stripe ]) {
6453+ logmsg (LOGMSG_INFO ,
6454+ "%s: increased stripe %d resume genid from %llx (%lld) to %llx (%lld) per shard %s\n" , __func__ ,
6455+ stripe , retros -> resume_genids [stripe ], retros -> resume_genids [stripe ], genid , genid ,
6456+ sc -> tablename );
6457+ retros -> resume_genids [stripe ] = genid ;
6458+ }
6459+ }
6460+ }
6461+
64086462 /* alter existing shard */
64096463 arg -> indx = 0 ;
64106464 arg -> pos = FIRST_SHARD | LAST_SHARD ;
@@ -6416,6 +6470,8 @@ static int _process_partitioning_retro(timepart_sc_arg_t *arg)
64166470 db -> sharding_func = timepart_retro_route ;
64176471 sc -> newpartition = newpartition ;
64186472 sc -> force_rebuild = 1 ;
6473+ /* run this async, this can be in upgrade thread */
6474+ sc -> nothrevent = 0 ;
64196475 for (int jj = 0 ; jj < retros -> n ; jj ++ ) {
64206476 logmsg (LOGMSG_USER , "PARTITION %s shard %d time %u name %s\n" , arg -> part_name , jj , retros -> limits [jj ],
64216477 (jj < (retros -> n - 1 )) ? retros -> ss [jj ]-> tablename : arg -> part_name );
0 commit comments