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

ASF GitHub Bot commented on PHOENIX-3254:
-----------------------------------------

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

    https://github.com/apache/phoenix/pull/211#discussion_r80916280
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
 ---
    @@ -1499,6 +1502,53 @@ public void createTable(RpcController controller, 
CreateTableRequest request,
                             cell.getTimestamp(), 
Type.codeToType(cell.getTypeByte()), bytes);
                         cells.add(viewConstantCell);
                     }
    +                Short indexId = null;
    +                if (request.hasAllocateIndexId() && 
request.getAllocateIndexId()) {
    +                    String tenantIdStr = tenantIdBytes.length == 0 ? null 
: Bytes.toString(tenantIdBytes);
    +                    final Properties props = new Properties();
    +                    UpgradeUtil.doNotUpgradeOnFirstConnection(props);
    +                    try (PhoenixConnection connection = 
DriverManager.getConnection(MetaDataUtil.getJdbcUrl(env), 
props).unwrap(PhoenixConnection.class)){
    +                    PName physicalName = parentTable.getPhysicalName();
    +                    int nSequenceSaltBuckets = 
connection.getQueryServices().getSequenceSaltBuckets();
    +                    SequenceKey key = 
MetaDataUtil.getViewIndexSequenceKey(tenantIdStr, physicalName,
    +                            nSequenceSaltBuckets, 
parentTable.isNamespaceMapped() );
    +                        // TODO Review Earlier sequence was created at 
(SCN-1/LATEST_TIMESTAMP) and incremented at the client 
max(SCN,dataTable.getTimestamp), but it seems we should
    +                        // use always LATEST_TIMESTAMP to avoid seeing 
wrong sequence values by different connection having SCN
    +                        // or not. 
    +                    long sequenceTimestamp = HConstants.LATEST_TIMESTAMP;
    +                    try {
    +                        
connection.getQueryServices().createSequence(key.getTenantId(), 
key.getSchemaName(), key.getSequenceName(),
    --- End diff --
    
    @ankitsinghal  This patch introducing inter table rpc calls but seems it's 
needed. What do you think of moving create sequence to meta data client and 
perform sequence increment alone here? So that atleast we can reduce the rpc 
calls here.


> IndexId Sequence is incremented even if index exists already.
> -------------------------------------------------------------
>
>                 Key: PHOENIX-3254
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-3254
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Ankit Singhal
>            Assignee: Ankit Singhal
>         Attachments: PHOENIX-3254.patch, PHOENIX-3254_wip.patch
>
>
> As we are incrementing sequence at the client even if we are not going to 
> create a index (in case index already exists and user is using CREATE INDEX 
> IF NOT EXISTS) or DDL failed in later stage(due to parent table not found or 
> something).
> If this keeps on happening then user may reach the limit of Short.MAX_VALUE 
> and TOO_MANY_INDEXES exception will be thrown if user tries to create a new 
> index.
> To prevent, this we should increment sequences when we are about to create a 
> index at server.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to