8000 GalleyVector: do not predict unbounded stamp size, when we have only … · postgrespro/libblobstamper@c43fc47 · GitHub
[go: up one dir, main page]

Skip to content

Commit c43fc47

Browse files
GalleyVector: do not predict unbounded stamp size, when we have only one ubounded stamp. It will take all space anyway
1 parent 7dcc092 commit c43fc47

File tree

5 files changed

+87
-27
lines changed
  • < 8000 div id=":Rdddab:" class="PRIVATE_TreeView-item-content prc-TreeView-TreeViewItemContent-f0r0b">blobstamper
  • t
  • 5 files changed

    +87
    -27
    lines changed

    blobstamper/Makefile

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,10 +11,10 @@ stamp_pg_type_ts.o \
    1111

    1212

    1313
    %.o: %.cpp $(DEPS)
    14-
    $(CXX) -c -g $(CFLAGS) $<
    14+
    $(CXX) -c -g $(CXXFLAGS) $<
    1515

    1616
    %.o: %.c $(DEPS)
    17-
    $(CC) -c -g $(CXXFLAGS) $<
    17+
    $(CC) -c -g $(CFLAGS) $<
    1818

    1919

    2020
    all: $(ALL_OBJS)

    blobstamper/galley.cpp

    Lines changed: 30 additions & 23 deletions
    Original file line numberDiff line numberDiff line change
    @@ -155,21 +155,6 @@ GalleySeries::extract_internal(Blob &blob)
    155155
    return res;
    156156
    }
    157157

    158-
    /*
    159-
    class GalleyVector : public GalleyBase
    160-
    {
    161-
    protected:
    162-
    std::vector<std::reference_wrapper<StampBase>> stamps;
    163-
    public:
    164-
    GalleyVector(std::vector<std::reference_wrapper<StampBase>> arg) : stamps(arg) {};
    165-
    std::vector<Blob> extract_internal(Blob &blob);
    166-
    std::vector<std::string> ExtractStr(Blob &blob);
    167-
    // std::list<void *> ExtractBin(Blob &blob);
    168-
    169-
    int minSize() override {return -2;}; // FIXME
    170-
    int maxSize() override {return -3;}; //FIXME /* Sereies always takes as much data as it can take */
    171-
    /*};*/
    172-
    173158
    std::vector<Blob>
    174159
    GalleyVector::extract_internal(Blob &blob)
    175160
    {
    @@ -181,6 +166,9 @@ GalleyVector::extract_internal(Blob &blob)
    181166
    bool has_variated_stamps = false;
    182167
    bool has_unbounded_stamps = false;
    183168

    169+
    int unbounded_count = 0;
    170+
    int variated_count = 0;
    171+
    184172
    /* Loop throight stamps calculating total sizes and seeing what kind of stamps do we have*/
    185173
    for(StampBase & s : stamps)
    186174
    {
    @@ -189,14 +177,19 @@ GalleyVector::extract_internal(Blob &blob)
    189177
    {
    190178
    max_varited_total_size += s.maxSize() - s.minSize();
    191179
    has_variated_stamps = true;
    192-
    fixed_total_size += ORACLE_SIZE;
    180+
    variated_count++;
    193181
    }
    194182
    if (s.isUnbounded())
    195183
    {
    196184
    has_unbounded_stamps = true;
    197-
    fixed_total_size += ORACLE_SIZE;
    185+
    unbounded_count++;
    198186
    }
    199187
    }
    188+
    fixed_total_size += ORACLE_SIZE * variated_count; /* We will predict stamp size for each variated stamp */
    189+
    190+
    if (unbounded_count > 1) /* One unbounded stamp will take all data. Nothing to predict */
    191+
    fixed_total_size += ORACLE_SIZE * unbounded_count;
    192+
    200193

    201194
    /* If we have both variated and unbounded stamp we will need oracle to devide availabe data between them */
    202195
    if (has_variated_stamps && has_unbounded_stamps)
    @@ -236,10 +229,16 @@ GalleyVector::extract_internal(Blob &blob)
    236229
    double modifier = 0;
    237230
    if (!s.isFixedSize())
    238231
    {
    239-
    ORACLE_TYPE * oracle = (ORACLE_TYPE *) blob.ShiftSingleStampBin(oracle_stamp);
    240-
    o_value = * oracle;
    241-
    free(oracle);
    242-
    modifier = (double) o_value / (double) ORACLE_MAX;
    232+
    if (s.isUnbounded() && unbounded_count <=1 )
    233+
    {
    234+
    modifier = 1; //Nothing to predict, it will use all space
    235+
    } else
    236+
    {
    237+
    ORACLE_TYPE * oracle = (ORACLE_TYPE *) blob.ShiftSingleStampBin(oracle_stamp);
    238+
    o_value = * oracle;
    239+
    free(oracle);
    240+
    modifier = (double) o_value / (double) ORACLE_MAX;
    241+
    }
    243242
    if (s.isUnbounded())
    244243
    {
    245244
    total_unbounded_modifiers += modifier;
    @@ -328,6 +327,9 @@ GalleyVector::minSize()
    328327
    bool has_variated_stamps = false;
    329328
    bool has_unbounded_stamps = false;
    330329

    330+
    int unbounded_count = 0;
    331+
    int variated_count = 0;
    332+
    331333
    int res = 0;
    332334

    333335
    /* Loop throight stamps calculating total sizes and seeing what kind of stamps do we have*/
    @@ -337,17 +339,22 @@ GalleyVector::minSize()
    337339
    if (s.isVariated())
    338340
    {
    339341
    has_variated_stamps = true;
    340-
    res += ORACLE_SIZE; //Each variated stamp needs an oracle to predict it's size
    342+
    variated_count++;
    341343
    }
    342344
    if (s.isUnbounded())
    343345
    {
    344346
    has_unbounded_stamps = true;
    345-
    res += ORACLE_SIZE; //Each unbounded stamp needs an oracle to predict it's size
    347+
    unbounded_count++;
    346348
    }
    347349
    }
    348350
    if (has_variated_stamps && has_unbounded_stamps)
    349351
    res += ORACLE_SIZE; // Need another oracle to predict how space is devided between variated and unbounded stamps
    350352

    353+
    res += ORACLE_SIZE * variated_count; /* We will predict stamp size for each variated stamp */
    354+
    355+
    if (unbounded_count > 1) /* One unbounded stamp will take all data. Nothing to predict */
    356+
    res += ORACLE_SIZE * unbounded_count;
    357+
    351358
    return res;
    352359
    }
    353360

    t/300-galley.cpp

    Lines changed: 43 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -18,7 +18,7 @@ char longer_sample[]="z1234567*89abcde&fghijklmnopqrstuvwxyzAB%CDEFGHIJKLMNOPQRS
    1818
    int
    1919
    main()
    2020
    {
    21-
    TEST_START(46);
    21+
    TEST_START(53);
    2222
    /* Test Galley Sereies with fixed size stampp*/
    2323
    { /* 1..4 */
    2424
    std::string expected1 = "12";
    @@ -314,5 +314,47 @@ main()
    314314
    is(galley.maxSize(), -1, "GalleyVector, mixed types stamps: galley max size is ok");
    315315
    }
    316316

    317+
    /* Test Galley Vector, single unbounded stamp will use all data with no oracle to predict it*/
    318+
    { /* 47 .. 53*/
    319+
    320+
    char sample[]="z1234567*89abcde&fghijklmnopqrstuvwxyzAB%CDEFGHIJKLMNOPQRSTUVWXYZ!";
    321+
    322+
    std::string expected1 = "z1"; // first f_stamp
    323+
    std::string expected2 = "(23, 45, 67, *8, 9a, bc, de, &f, gh, ij, kl, mn, op, qr, st, uv, wx, yz, AB, %C, DE, FG, HI, JK, LM, NO, PQ, RS, TU, VW, XY)"; // u_stamp
    324+
    std::string expected3 = "Z!"; // second f_stamp
    325+
    326+
    Blob blob(sample, strlen(sample));
    327+
    328+
    329+
    StampTwoChars f_stamp;
    330+
    StampTwoCharsList u_stamp;
    331+
    332+
    std::vector<std::reference_wrapper<StampBase>> stamps;
    333+
    stamps.push_back(f_stamp);
    334+
    stamps.push_back(u_stamp);
    335+
    stamps.push_back(f_stamp);
    336+
    337+
    GalleyVector galley(stamps);
    338+
    339+
    std::vector<std::string> res = galley.ExtractStr(blob);
    340+
    std::string str;
    341+
    342+
    str = res[0];
    343+
    is(str, expected1, "GalleyVector, mixed type stamps 2: First unbounded stamp is ok");
    344+
    345+
    str = res[1];
    346+
    is(str, expected2, "GalleyVector, mixed type stamps 2: Fist varieded stamp is ok");
    347+
    348+
    str = res[2];
    349+
    is(str, expected3, "GalleyVector, mixed type stamps 2: Second variated stamp is ok");
    350+
    351+
    is(res.size(), 3, "GalleyVector, mixed type stamps 2: The vector has only three elements ");
    352+
    353+
    is(blob.Size(), 0 , "GalleyVector 2: will use all data if we have at least one unbounded stamp");
    354+
    355+
    is(galley.minSize(), f_stamp.minSize()*2 + u_stamp.minSize() , "GalleyVector 2, mixed types stamps: galley min size is ok");
    356+
    is(galley.maxSize(), -1, "GalleyVector, mixed types stamps 2: galley max size is ok");
    357+
    }
    358+
    317359
    TEST_END;
    318360
    }

    t/Makefile

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -3,7 +3,7 @@ ACK := ack
    33
    LIBTAPPP := ../libtappp/libtap++.so
    44
    WARNINGS := -Wall -Wextra -Weffc++
    55
    DEBUG := -ggdb3 -DDEBUG
    6-
    CXXFLAGS := $(DEBUG) $(WARNINGS) -fPIC
    6+
    #CXXFLAGS := $(DEBUG) $(WARNINGS) -fPIC
    77
    PREFIX := /usr/local
    88
    LIBRARY_VAR := LD_LIBRARY_PATH
    99
    TEST_GOALS := ./00-sanity.t \

    test_with_sanitizers.sh

    Lines changed: 11 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,11 @@
    1+
    #!/bin/sh
    2+
    3+
    export CC=clang
    4+
    export CXX=clang++
    5+
    export CFLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=undefined"
    6+
    export CXXFLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=undefined"
    7+
    export LDFLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=undefined"
    8+
    9+
    make clean
    10+
    make
    11+
    make test

    0 commit comments

    Comments
     (0)
    0