Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

[DB] Support SQL Field Query in Alcor #703

Merged
merged 61 commits into from
Dec 2, 2021

Conversation

pkommoju
Copy link
Contributor

Ignite SqlFieldQuery changes.

  • Ignite allows fast searching of the KV store using a field (secondary key/index) in the value field through SQL interface.
  • This change is almost entirely in the commonlib (Ignite interface layer).
  • To enable this feature, add the annotation @QuerySqlField(index = true) to the field to index on.
  • When a class member is annotated with @QuerySqlField(index = true), a get() using filterParams will use SQLFieldsQuery if all the filter params are also in the set of QuerySqlFields.
  • If fields m1, m2, and m3 are in the QuerySqlField set, in that order, and thet get supplies only m1, or m1 and m2, or all three, then Ignite interface will use SqlFieldsQuery, otherwise it will fallback to Scan Query. This is called index prefix search.
  • One optimization not in this commit is to cache the queries and reuse them. If needed, this optimization can be added later.
  • For an example use, look at web...NodeInfo class. and services/sqlquery and services/scanquery.

pkommoju and others added 30 commits May 12, 2021 11:34
Add document about transactional semantics for Alcor Caches in general
and spefically about Ignite Caches.

import java.util.Objects;

public class CustomerResource extends Resource {

@JsonProperty("project_id")
// @QuerySqlField(index = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkommoju If we don't need add @QuerySqlField here, please remove it and the import.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidLiu506 Please confirm, if we need the index on project_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove it after Dahai confirms that it is no longer needed.

Copy link
Contributor

@DavidLiu506 DavidLiu506 Nov 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it first. Add it back if there are scenarios.

Removed the commented annotation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just leave comment here. If we need it in the future, we can enable it then.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

private String id;

@JsonProperty("node_name")
// @QuerySqlField(index = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkommoju and @DavidLiu506 Do we need index for node_id and node_name? If not, please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node_name needs index. In fact NMM swagger and the getAllNodes allows querying on any combination of name, mac, local ip, ncm_id. I should add index on all of them. id may not be needed if getAllNodes doesn't use SCAN query if querying by only id. I will check this path and remove index on id if this is so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed index on id, added it on localIp, macAddress, ncm_id.

}

@DurationStatistics
public <E1, E2> Map<K, V> getBySqlFieldsAll(Map<String, Object[]> filterParams) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkommoju Do we need to throw exception from this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need. runSqlFieldsQuery will throw any exception anyway. Just need to add throws CacheException.

if (sqlFields != null && sqlFields.size() != 0) {
this.cache = getOrCreateIndexedCache(igniteClient, className, clientCacheConfig, null);
if (this.cache == null) {
logger.log(Level.WARNING, "Create cache for client " + className + " with index failed, falling back");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkommoju How to handle falling back if this.cache=null ? just use igniteClient.getOrCreateCache(clientCacheConfig) instead here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am logging it as a warning message here. Few lines below, if this.cache is null, we call igniteClient.getOrCreateCache(clientCacheConfig). This call could also be because the the cache is not setup for SQLFieldsQuery in addition to handling the case where it is setup but something went wrong. Didn't want to have the call in two places.

@xieus xieus changed the title Sqlfieldquery [DB] Support SQL Field Query in Alcor Nov 29, 2021
@xieus xieus added this to the Version 1.0.2021.12.30 milestone Nov 29, 2021
@xieus
Copy link
Contributor

xieus commented Nov 29, 2021

@pkommoju There is a conflict with existing master after PR #704 was merged.

* Set index value inline size to length of GUUID to avoid multiple
  index page fetch penalty.
* Remove unecessary logging.
* Check only once to see if SQL index can be created.
@lgtm-com
Copy link

lgtm-com bot commented Nov 30, 2021

This pull request introduces 2 alerts when merging 5a1ea86 into a843622 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

@lgtm-com
Copy link

lgtm-com bot commented Nov 30, 2021

This pull request introduces 2 alerts when merging af58b49 into a843622 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null


import java.util.Objects;

public class CustomerResource extends Resource {

@JsonProperty("project_id")
// @QuerySqlField(index = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just leave comment here. If we need it in the future, we can enable it then.

@lgtm-com
Copy link

lgtm-com bot commented Nov 30, 2021

This pull request introduces 2 alerts when merging 02f04a5 into a843622 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

Copy link
Contributor

@cj-chung cj-chung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkommoju Another comment: please rename the scanquery service to a name like scanquery_test_nodemanager.

In that case, should the sqlquery service also be renamed as sqlquery_test_nodemanager, to be consistant?

this.cache = getOrCreateIndexedCache(igniteClient, className, clientCacheConfig, null);
if (this.cache == null) {
logger.log(Level.WARNING, "Create cache for client " + className + " with index failed, falling back");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add if (!checkedForSqlFields)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is a few lines above.

}
private Map<String, SqlField> sqlFields = null; // needed for index creation and querying
private List<String> sqlColumns = null; // needed for constructing indexes in specified order
// so that a prefix query can use indexed search.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove sqlColumns , sqlFields use LinkedHashMap

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed sqlColumns and changed Map to LinkedHashMap.


import java.util.Objects;

public class CustomerResource extends Resource {

@JsonProperty("project_id")
// @QuerySqlField(index = true)
Copy link
Contributor

@DavidLiu506 DavidLiu506 Nov 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it first. Add it back if there are scenarios.

Removed the commented annotation.

@@ -20,13 +20,15 @@
import com.futurewei.alcor.common.entity.CustomerResource;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ignite.cache.query.annotations.QuerySqlField;

import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_ABSENT)
public class PortEntity extends CustomerResource {
@JsonProperty("network_id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add index

@lgtm-com
Copy link

lgtm-com bot commented Dec 2, 2021

This pull request introduces 2 alerts when merging eb19113 into a843622 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

@lgtm-com
Copy link

lgtm-com bot commented Dec 2, 2021

This pull request introduces 2 alerts when merging 3cf7110 into a843622 - view on LGTM.com

new alerts:

  • 2 for Dereferenced variable may be null

Copy link
Contributor

@cj-chung cj-chung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@xieus xieus merged commit 03bed53 into futurewei-cloud:master Dec 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants