Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/resolve from storage #3441

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from
Draft

Conversation

thoniTUB
Copy link
Collaborator

@thoniTUB thoniTUB commented May 15, 2024

This pr makes the CentralRegistry obsolete, by resolving ids directly from the storage.

Before, the CentralResgistry held all objects in Memory so no memory optimized caching is possible.
Removing the registry removes one central point were hard references to all objects where held.

The CentralRegistry was used by deserializers (MetaIdReferenceDeserializer, NsIdReferenceDeserializer) to resolve incomming Ids in JSONs to concrete objects.
The CentralRegistry was however not a singleton, as every Storage (MetaStorage, NamespaceStorage, WorkerStorage) had one.
It is replaced by the NsIdResolver interface, which is implemented by NamespaceStorage, WorkerStorage and DatasetRegistry.

The MetaIdReferenceDeserializer just uses the MetaStorage directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hier habe ich den Deserializer angepasst, so dass nicht erst zum Zeitpunkt der Deserializierung der IdResolver aus den Injectables rausgesucht wird, sondern schon während der Instantiierung

@@ -18,7 +18,7 @@ public class BinaryJacksonCoder implements CQCoder<NetworkMessage<?>> {
private final ObjectWriter writer;
private final ObjectReader reader;

public BinaryJacksonCoder(IdResolveContext datasets, Validator validator, ObjectMapper objectMapper) {
public BinaryJacksonCoder(NsIdResolver datasets, Validator validator, ObjectMapper objectMapper) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IdResolveContext konnte MetaId und NamespacedIds resolven. MetaIds werden aber gar nicht gebraucht in der Kommunikation zwischen Manager und Shards, deshalb gibt es hier nur einen NsIdResolver

@@ -196,4 +197,24 @@ public void addFormConfig(FormConfig formConfig) {
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(MetaStorage.class, this);
}

public <ID extends Id<VALUE>, VALUE extends Identifiable<?>> VALUE get(ID id) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Diese get Methoden in den Storages imitieren einfach das ehemalöige getOptional der CentralRegistry.

@thoniTUB thoniTUB requested a review from SebChmie May 23, 2024 09:15
Copy link
Collaborator

@SebChmie SebChmie left a comment

Choose a reason for hiding this comment

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

Sieht gut aus 😃

concepts.remove(id);
}

public Collection<Concept<?>> getAllConcepts() {
return concepts.getAll();
}

public <ID extends Id<VALUE> & NamespacedId, VALUE extends Identifiable<?>> VALUE get(ID id) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
public <ID extends Id<VALUE> & NamespacedId, VALUE extends Identifiable<?>> VALUE get(ID id) {
@SuppressWarnings("unchecked")
public <ID extends Id<VALUE> & NamespacedId, VALUE extends Identifiable<?>> VALUE get(ID id) {

super.clear();
centralRegistry.clear();
}

private void decorateDatasetStore(SingletonStore<Dataset> store) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wofür gibt es private void decorateDatasetStore, private void decorateSecondaryIdDescriptionStore, private void decorateTableStore und private void decorateImportStore

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Die Methoden wurden für eine etwaige Initialisierung eines Objektes angelegt. Viele Objekte müssen aber nicht initialisiert werden und für andere habe ich denke ich eine bessere Lösung gefunden. Also die Funktionen können potentiell weg

@@ -114,19 +114,21 @@ public record InfoCardSelect(@NotNull String label, SelectId select, String desc
/**
* Defines a group of selects that will be evaluated per quarter and year in the requested period of the entity-preview.
*/
public record TimeStratifiedSelects(@NotNull String label, String description, @NotEmpty List<InfoCardSelect> selects){
public record TimeStratifiedSelects(@NotNull String label, String description, @NotEmpty List<InfoCardSelect> selects) {
}

@ValidationMethod(message = "Selects may be referenced only once.")
@JsonIgnore
public boolean isSelectsUnique() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Intellij meldet das diese ValidationMethods nicht benutzt werden.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh das kann natürlich sein, mir wurde die Warnung nicht angezeigt.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Du musst Intellij einstellen, dass es bei dieser Anno kein unused meldet. Die werden automatisch ausgeführt bei Validierung

}

@ValidationMethod(message = "Labels must be unique.")
@JsonIgnore
public boolean isLabelsUnique() {
return timeStratifiedSelects.stream().map(TimeStratifiedSelects::selects).flatMap(Collection::stream).map(InfoCardSelect::label).distinct().count() == timeStratifiedSelects.stream().map(TimeStratifiedSelects::selects).flatMap(Collection::stream).count();
return timeStratifiedSelects.stream().map(TimeStratifiedSelects::selects).flatMap(Collection::stream).map(InfoCardSelect::label).distinct().count()
== timeStratifiedSelects.stream().map(TimeStratifiedSelects::selects).flatMap(Collection::stream).count();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
== timeStratifiedSelects.stream().map(TimeStratifiedSelects::selects).flatMap(Collection::stream).count();
== timeStratifiedSelects.stream().map(TimeStratifiedSelects::selects).mapToLong(Collection::size).sum();

Copy link
Collaborator

@awildturtok awildturtok left a comment

Choose a reason for hiding this comment

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

-300 Zeilen code und es ist jetzt direkter gekoppelt, nice!

@@ -197,13 +202,21 @@ public void resolve(QueryResolveContext context) {
* <p>
* The resolved filter instructs the frontend on how to render and serialize the filter value using the {@link Filter#createFrontendConfig(com.bakdata.conquery.models.config.ConqueryConfig)} method. The filter must implement {@link GroupFilter} and provide the type information of the value to correctly deserialize the received object.
*/
public static class GroupFilterDeserializer extends StdDeserializer<GroupFilterValue> {
private final NsIdReferenceDeserializer<FilterId, Filter<?>> nsIdDeserializer = new NsIdReferenceDeserializer<>(Filter.class, null, FilterId.class);
public static class GroupFilterDeserializer extends StdDeserializer<GroupFilterValue> implements ContextualDeserializer {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ich weiß, es ist bisschen dein Baby, aber kann das nicht auch ganz weg?


@Override
public VALUE fromString(String value) {
final ID id = idParser.parse(value);

return registry.resolve(id);
return storage.get(id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

@@ -1,77 +0,0 @@
package com.bakdata.conquery.io.storage;
Copy link
Collaborator

Choose a reason for hiding this comment

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

gelöscth, weil du caching verschieben willst?

@@ -196,4 +191,24 @@ public void addFormConfig(FormConfig formConfig) {
public MutableInjectableValues inject(MutableInjectableValues values) {
return values.add(MetaStorage.class, this);
}

public <ID extends Id<VALUE>, VALUE extends Identifiable<?>> VALUE get(ID id) {
if (id instanceof ManagedExecutionId executionId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

können nicht die ids das getten machen?


@Override
public <ID extends Id<VALUE> & NamespacedId, VALUE extends Identifiable<?>> VALUE get(ID id) {
if (id instanceof InternToExternMapperId castId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

würde den access den ids überlassen

Comment on lines +72 to +74
datasetStorage.close();

return createNamespace(datasetStorage, metaStorage);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Formatierun stimmt hier nicht

Comment on lines +130 to +131
return values.add(NsIdResolver.class, this)
.add(this.getClass(), this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

sind beide injections notwendig?

doAnswer(invocation -> {
throw new UnsupportedOperationException("Not yet implemented");
}).when(namespacesMock).getOptional(any());
// TODO
Copy link
Collaborator

Choose a reason for hiding this comment

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

noch offen?

Comment on lines +227 to +232
final WorkerStorage workerStorage = getWorkerStorage();

CentralRegistry registry = getMetaStorage().getCentralRegistry();

registry.register(dataset);
registry.register(startCol);
registry.register(endCol);
registry.register(compoundCol);
registry.register(table);
registry.register(imp);
registry.register(bucket);
workerStorage.updateDataset(dataset);
workerStorage.addTable(table);
workerStorage.addImport(imp);
workerStorage.addBucket(bucket);
Copy link
Collaborator

Choose a reason for hiding this comment

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

fett

@NotNull
public static TreeConcept createConcept(CentralRegistry registry, Dataset dataset) {
public static TreeConcept createConcept(Dataset dataset, NamespacedStorage ... storages) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

wieso können das mehrere Storages sein?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants