tephra-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (TEPHRA-287) ActionChange.getChangeKey() not implemented correctly
Date Mon, 07 May 2018 03:49:00 GMT

    [ https://issues.apache.org/jira/browse/TEPHRA-287?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16465402#comment-16465402
] 

ASF GitHub Bot commented on TEPHRA-287:
---------------------------------------

Github user poornachandra commented on a diff in the pull request:

    https://github.com/apache/incubator-tephra/pull/75#discussion_r186321022
  
    --- Diff: tephra-core/src/main/java/org/apache/tephra/AbstractTransactionAwareTable.java
---
    @@ -88,21 +93,105 @@ public void updateTx(Transaction tx) {
         Collection<byte[]> txChanges = new TreeSet<byte[]>(UnsignedBytes.lexicographicalComparator());
         for (Set<ActionChange> changeSet : changeSets.values()) {
           for (ActionChange change : changeSet) {
    -        txChanges.add(getChangeKey(change.getRow(), change.getFamily(), change.getQualifier()));
    +        byte[] row = change.getRow();
    +        byte[] fam = change.getFamily();
    +        byte[] qual = change.getQualifier();
    +        txChanges.add(getChangeKey(row, fam, qual));
    +        if (pre014ChangeSetKey) {
    +          txChanges.add(getChangeKeyWithoutSeparators(row, fam, qual));
    +        }
           }
         }
         return txChanges;
       }
     
    +  /**
    +   * @param vint long to make a vint of.
    +   * @return long in vint byte array representation
    +   * We could alternatively make this abstract and
    +   * implement this method as Bytes.vintToBytes(long) in
    +   * every compat module. 
    +   */
    +  protected byte [] getVIntBytes(final long vint) {
    +    long i = vint;
    +    int size = WritableUtils.getVIntSize(i);
    +    byte [] result = new byte[size];
    +    int offset = 0;
    +    if (i >= -112 && i <= 127) {
    +      result[offset] = (byte) i;
    +      return result;
    +    }
    +
    +    int len = -112;
    +    if (i < 0) {
    +      i ^= -1L; // take one's complement'
    +      len = -120;
    +    }
    +
    +    long tmp = i;
    +    while (tmp != 0) {
    +      tmp = tmp >> 8;
    +    len--;
    +    }
    +
    +    result[offset++] = (byte) len;
    +
    +    len = (len < -120) ? -(len + 120) : -(len + 112);
    +
    +    for (int idx = len; idx != 0; idx--) {
    +      int shiftbits = (idx - 1) * 8;
    +      long mask = 0xFFL << shiftbits;
    +      result[offset++] = (byte) ((i & mask) >> shiftbits);
    +    }
    +    return result;
    +  }
    +
    +  /**
    +   * The unique bytes identifying what is changing. We use the
    +   * following structure:
    +   * ROW conflict level: <table_name><0 byte separator><row key>
    +   * since we know that table_name cannot contain a zero byte.
    +   * COLUMN conflict level: <table_name><length of family as vint><family>
    --- End diff --
    
    Based on the implementation below this should be `COLUMN conflict level: <table_name>0<length
of family as vint><family>...`



> ActionChange.getChangeKey() not implemented correctly
> -----------------------------------------------------
>
>                 Key: TEPHRA-287
>                 URL: https://issues.apache.org/jira/browse/TEPHRA-287
>             Project: Tephra
>          Issue Type: Bug
>            Reporter: James Taylor
>            Assignee: James Taylor
>            Priority: Major
>             Fix For: 0.14.0-incubating
>
>         Attachments: TEPHRA-287_v1.patch, TEPHRA-287_v2.patch, TEPHRA-287_v3.patch
>
>
> The ActionChange.getChangeKey() simply concatenates together the row key, family, and
qualifier which could lead to incorrect conflicting keys. For example (rowKey='a', family='bc')
would conflict with (rowKey='ab', family='c'). A simple fix would be to prefix each part with
the byte length of each part.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message