0
votes

Using ignite 2.9.x

I have two BinaryObject caches with one serves as a parent and the other as a child with an affinity key to the parent, this way I can colocate all relevant records on the same node.

I then want to select all child records based on the parent key. At the moment based on a 3 nodes cluster, the search time is linearly growing as I add new parent and child records (child records per parent is fixed (1000)).

I wonder if there is a way to add an index on the child cache parent property (asset) so the scan will scale more efficiently.

Production ..> Asset (asset)

  • can I define an index on the Production cache using the parent key asset?
  • what would this config look like?
  • How would the query change?
  • Should I use the AffinityKey in this case (how)?
    IgniteCache<Integer, BinaryObject> productions = ignite.cache("productions").withKeepBinary();

    Map<LocalDate, Double> totals = new HashMap<>();

    try (QueryCursor<Cache.Entry<BinaryObject, BinaryObject>> cursor =
        productions.query(
            new ScanQuery<BinaryObject, BinaryObject>().setLocal(true).setFilter(this::apply))) {
      for (Cache.Entry<BinaryObject, BinaryObject> entry : cursor) {
        OffsetDateTime timestamp = entry.getValue().field("timestamp");
        double productionMwh = entry.getValue().field("productionMwh");

        totals.computeIfPresent(
            timestamp.toLocalDate().withDayOfMonth(1),
            (localDate, aDouble) -> aDouble + productionMwh);
        totals.computeIfAbsent(
            timestamp.toLocalDate().withDayOfMonth(1), localDate -> productionMwh);
      }
    }

  private boolean apply(BinaryObject id, BinaryObject production) {
    return key == ((Integer) production.field("asset"));
  }

1

1 Answers

0
votes

The only way to implement efficient parent->child link is to define SQL table and SQL index for your data. You can still collocate such data on affinity column.