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

Fixed the update process by also complete places before updating #369

Closed
wants to merge 2 commits into from

Conversation

hendrikmoree
Copy link
Contributor

Currently updates aren't correctly processed. Places are incomplete, and a lot warning are given because a place can be deleted and also tried to updateOrCreate afterwards.

This fixes both issues.

@hendrikmoree
Copy link
Contributor Author

hendrikmoree commented Oct 17, 2018

default:
LOGGER.error(String.format("Unknown index status %d", place.getIndexdStatus()));
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at this again, the different cases need a bit more consideration.

For 'case 100' (object was deleted), export.getByPlaceId() shouldn't even be called because we already know that the placeID won't exist anymore. (That was wrong before as well but is worth fixing while changing this code.)

More importantly, for the 'case 2', the code does not catch when a housenumber gets deleted from the batch of housenumbers for that placeID because the code only updates the ones that exist after the update. The most simple solution here is to always call a delete with a subsequent create for case 2. I don't know what the performance impact of such a solution would be.

In any case, the delete() in 'case 2' should be moved out of the loop. isUsefulForIndex() evaluates always to the same value for the elements of updatesDocs and calling delete() multiple times for the same placeID is inefficient, if not harmful.

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've fixed the case '100' issue.

I'm not really sure how to fix the other case '2' issue. We're already running some months with this code, so it doesn't seems to be harmful. This PR looks quite important to me, because the update process is really broken now, if anyone now how to fix it, it would be great.

Copy link
Contributor

@simonpoole simonpoole Jan 23, 2019

Choose a reason for hiding this comment

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

@hendrikmoree I think @lonvia was thinking about something along

                    final List<PhotonDoc> updatedDocs = exporter.getByPlaceId(place.getPlaceId());
                    if (indexdStatus == 2 && updatedDocs.size() > 1) {
                        updater.delete(placeId);
                    }
                    boolean wasUseful = false;
                    for (PhotonDoc updatedDoc : updatedDocs) {
                        switch (indexdStatus) {
                        case 1:
                            if (updatedDoc.isUsefulForIndex()) {
                                updater.create(updatedDoc);
                            }
                            break;
                        case 2:
                            if (updatedDoc.isUsefulForIndex()) {
                                updater.updateOrCreate(updatedDoc);
                                wasUseful = true;
                            }
                            break;
                        default:
                            LOGGER.error(String.format("Unknown index status %d", indexdStatus));
                            break;
                        }
                    }
                    if (indexdStatus == 2 && !wasUseful) {
                        updater.delete(placeId);
                    }

This is better, but still has a couple of cases that are not covered, for example that the object now only has 1 house number and used to have multiple.

To make it really correct you would need to remove the updatedDocs.size() > 1 test, which means that every update would first delete all documents with the referenced place id,

@systemed systemed mentioned this pull request Jan 21, 2019
@simonpoole
Copy link
Contributor

@lonvia @karussell my question here would be: do we really need the added complexity caused by expanding Nominatim objects with multiple house numbers in to multiple documents on import in the first place?

@lonvia
Copy link
Collaborator

lonvia commented Jan 23, 2019

They are needed to support address interpolations.

@simonpoole
Copy link
Contributor

simonpoole commented Jan 24, 2019

There are two issues that are not addressed by my rough code suggestion

  • interpolations were not being updated at all (this is simply an omission in the current code)
  • you can't call ...updateOrCreate after calling delete as, updateOrCreate checks if the documents exist to determine if to call update or create when submitting the action for batch execution, and as a result update will incorrectly be called instead of create.

I now have (I believe :-)) working code for this that addresses both issues. I'll refine it a bit more (are there any tests for the updater?) and then create a new PR if nobody disagrees.

@lonvia
Copy link
Collaborator

lonvia commented Feb 17, 2019

Superseded by #382. Closing here.

Thanks @hendrikmoree for the initial version.

@lonvia lonvia closed this Feb 17, 2019
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