[
https://issues.apache.org/jira/browse/PHOENIX-6506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17382108#comment-17382108
]
ASF GitHub Bot commented on PHOENIX-6506:
-----------------------------------------
virajjasani commented on a change in pull request #1261:
URL: https://github.com/apache/phoenix/pull/1261#discussion_r671302065
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
##########
@@ -5079,6 +5079,38 @@ private void
incrementSequenceValues(List<SequenceAllocation> sequenceAllocation
}
}
+ /**
+ * checks if sequenceAllocation's sequence there in sequenceMap, also
returns Global Sequences
+ * from Tenant sequenceAllocations
+ * @param sequenceAllocation
+ * @return
+ */
+
+ private Sequence getSequence(SequenceAllocation sequenceAllocation) {
+ SequenceKey key = sequenceAllocation.getSequenceKey();
+ if (key.getTenantId() == null) {
+ return sequenceMap.putIfAbsent(key, new Sequence(key));
+ } else {
+ Sequence sequence = sequenceMap.get(key);
+ if (sequence == null) {
+ for (Map.Entry<SequenceKey,Sequence> entry :
sequenceMap.entrySet()) {
+ if (compareSequenceKeysWithoutTenant(key, entry.getKey()))
{
+ return entry.getValue();
+ }
+ }
+ } else {
+ return sequence;
+ }
+ }
+ return null;
+ }
+
+ private boolean compareSequenceKeysWithoutTenant(SequenceKey key1,
SequenceKey key2) {
+ return key2.getTenantId() == null && (key1.getSchemaName() == null ?
key2.getSchemaName() == null :
+ key1.getSchemaName().equals(key2.getSchemaName())) &&
+ key1.getSequenceName().equals(key2.getSequenceName());
Review comment:
Here we are checking if key2 is global sequence right?
It's bit difficult to understand in one statement. Good to break it down,
something like
```
private boolean compareSequenceKeysWithoutTenant(SequenceKey
keyToCompare,
SequenceKey availableKey) {
boolean sameSchema = keyToCompare.getSchemaName() == null
? availableKey.getSchemaName() == null
:
keyToCompare.getSchemaName().equals(availableKey.getSchemaName());
if (!sameSchema) {
return false;
}
if (availableKey.getTenantId() != null) {
return false;
}
return
keyToCompare.getSequenceName().equals(availableKey.getSequenceName());
}
```
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
##########
@@ -5079,6 +5079,38 @@ private void
incrementSequenceValues(List<SequenceAllocation> sequenceAllocation
}
}
+ /**
+ * checks if sequenceAllocation's sequence there in sequenceMap, also
returns Global Sequences
+ * from Tenant sequenceAllocations
+ * @param sequenceAllocation
+ * @return
+ */
+
+ private Sequence getSequence(SequenceAllocation sequenceAllocation) {
+ SequenceKey key = sequenceAllocation.getSequenceKey();
+ if (key.getTenantId() == null) {
+ return sequenceMap.putIfAbsent(key, new Sequence(key));
+ } else {
+ Sequence sequence = sequenceMap.get(key);
+ if (sequence == null) {
+ for (Map.Entry<SequenceKey,Sequence> entry :
sequenceMap.entrySet()) {
+ if (compareSequenceKeysWithoutTenant(key, entry.getKey()))
{
+ return entry.getValue();
+ }
+ }
Review comment:
nit: replace with stream -> filter -> findfirst?
```
return sequenceMap.entrySet().stream()
.filter(entry -> compareSequenceKeysWithoutTenant(key,
entry.getKey()))
.findFirst()
.map(Entry::getValue)
.orElse(null);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
> Tenant Connection is not able to access/validate Global Sequences
> -----------------------------------------------------------------
>
> Key: PHOENIX-6506
> URL: https://issues.apache.org/jira/browse/PHOENIX-6506
> Project: Phoenix
> Issue Type: Bug
> Reporter: Lokesh Khurana
> Assignee: Lokesh Khurana
> Priority: Major
> Attachments: PHOENIX-6506-test.patch, PHOENIX-6506.patch
>
>
> In our test environment we were using sequence(created using global
> connection) in our Table, recently we updated that table to be MULTI_TENANT
> and both types of connections (tenant and global) are needs to upsert data
> into Table.
> Tenant connections are not able to upsert data into table as it is not able
> to validate sequence and getting SequenceNotFoundException.
> Adding patch with Test failing due to same scenario.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)