src/siri/db/series.c
/*
 * Re-allocations in this function can fail but are not critical.
 *
 * Note that 'series' can be destroyed when series->length has reached zero.
 */
Re-allocations in this function can fail but are not critical.
Note that 'series' can be destroyed when series->length has reached zero.
Re - allocations in this function can fail but are not critical . Note that ' series ' can be destroyed when series - > length has reached zero .
void siridb_series_remove_shard(
        siridb_t *__restrict siridb,
        siridb_series_t *__restrict series,
        siridb_shard_t *__restrict shard)
{
#ifdef DEBUG
    assert (shard->id % siridb->duration_num == series->mask);
#endif
    idx_t *__restrict idx;
    uint_fast32_t i, offset;
    i = offset = 0;
    for (   idx = series->idx;
            i < series->idx_len;
            i++, idx++)
    {
        if (idx->shard == shard)
        {
            siridb_shard_decref(shard);
            offset++;
            series->length -= idx->len;
        }
        else if (offset)
        {
            series->idx[i - offset] = series->idx[i];
        }
    }
    if (offset)
    {
        if (!series->length)
        {
            series->idx_len = 0;
            if (siridb_series_drop(siridb, series))
            {
                siridb_series_flush_dropped(siridb);
            }
        }
        else
        {
            series->idx_len -= offset;
            idx = (idx_t *) realloc(
                        series->idx,
                        series->idx_len * sizeof(idx_t));
            if (idx == NULL && series->idx_len)
            {
                log_error("Re-allocation failed while removing series from "
                        "shard index");
            }
            else
            {
                series->idx = idx;
            }
            uint64_t start = shard->id - series->mask;
            uint64_t end = start + siridb->duration_num;
            if (series->start >= start && series->start < end)
            {
                SERIES_update_start(series);
            }
            if (series->end < end && series->end > start)
            {
                SERIES_update_end(series);
            }
        }
    }
}
void siridb_series_remove_shard ( siridb_t * __restrict siridb , siridb_series_t * __restrict series , siridb_shard_t * __restrict shard ) { #ifdef DEBUG assert ( shard -> id % siridb -> duration_num == series -> mask ) ; #endif idx_t * __restrict idx ; uint_fast32_t i , offset ; i = offset = 0 ; for ( idx = series -> idx ; i < series -> idx_len ; i ++ , idx ++ ) { if ( idx -> shard == shard ) { siridb_shard_decref ( shard ) ; offset ++ ; series -> length -= idx -> len ; } else if ( offset ) { series -> idx [ i - offset ] = series -> idx [ i ] ; } } if ( offset ) { if ( ! series -> length ) { series -> idx_len = 0 ; if ( siridb_series_drop ( siridb , series ) ) { siridb_series_flush_dropped ( siridb ) ; } } else { series -> idx_len -= offset ; idx = ( idx_t * ) realloc ( series -> idx , series -> idx_len * sizeof ( idx_t ) ) ; if ( idx == NULL && series -> idx_len ) { log_error ( " " " " ) ; } else { series -> idx = idx ; } uint64_t start = shard -> id - series -> mask ; uint64_t end = start + siridb -> duration_num ; if ( series -> start >= start && series -> start < end ) { SERIES_update_start ( series ) ; } if ( series -> end < end && series -> end > start ) { SERIES_update_end ( series ) ; } } } }
Re-allocations in this function can fail but are not critical.
Re - allocations in this function can fail but are not critical .