-
Notifications
You must be signed in to change notification settings - Fork 43
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
Problem with subscriptions when orion container crashes or stops. #1708
Comments
ok, that's not good. Add the information of the creation of your subscriptions to this issue and let me know exactly what you do in order to see the problem. |
entity creation example:
entity subscription:
adding data to crate db:
if you do that it will create the entity and its subscription and add some data to it in the crate db. After that stop the orion ld container and start it again. If you try to add new data to the entity in crate db nothing will be added. Also for the variables in docker compose: |
ok, good. That I can work with. Giving a core context to the broker as a user context is not a very good idea.
Or, even better host your user context somewhere and just give the URL to it. |
Ok, thanks for the info I will take that into account and adjust the entity creation process. |
So, I found the error. I explain: So, if you follow my advice and stop using
I will of course proceed and fix my bug. |
I just fixed another issue, closely related to this one: #1715. |
Tested it just now. The problem remains. |
ok, pity ... :) Sorry for geing a bit AWOL lately. |
No problem. I am actually surprised by the interest you showed regarding the issues I am facing, you don't see that commitment often. Thank you for all your efforts. |
ok, in an issue coming from elsewhere, I just fixed a bug about repopulating the subscription cache on restart. |
Should I just pull again with latest tag? |
Yes, just don't leave "latest" in there. It's dangerous as "latest" keeps changing. |
Just checked again. The problem remains. |
ok, thanks. |
It works without @context and without link in the header |
Good. Also, avoid at all cost to use "inline" contexts. Also a very bad idea. My guess is you already tried that. The best approach is to host your user context somewhere and then give that URL in the Link header. |
I tried that solution with link you mentioned but it has several problems with backslashes in url and duplicate attrNames and more that I mentioned in detail in the other issue I had opened and we had discussed. So I still use @context. |
Ah, that, yeah I remember. |
Here are my requests: Create entity:
Create subscription:
the entity in mongo is saved like:
The problems start after I try to patch:
the mongo entity changes to:
notice how the attr names became 2:
Also if I patch again they will become 3 attr names instead of remaining one unique for each attribute like it happened with the old method of creating entities. I just wanted to replace with the latest value. The context is like this:
Also regarding the patch request I mentioned. Is creating duplicate entries in "attrNames": [ an intented functionality every time a patch request is made?
I noticed and you mentioned it as well that the mongo entity of context doesnt change from the original one after running the delete request. The attributes that were added to the context after the initial load are expanded correctly after I update the context in the site page and run the delete request. The problem I have is since the mongo db entity for context doesnt change that means if orion container stops or is deleted the attributes that were added to the context after the initial download wont be included in the context anymore and if I try to create a new entity with those attributes without reloading the context again they wont have the correct url. Is there a way to force orion to recreate the context entity in mongo as well as refreshing its context cache? If there isn't I guess I have to go back to the previous way of creating entities without link because my context is dynamic since users in my app can add attributes to the context when they create a new entity that has an attribute that doesnt exist in the context. The old method didn't have any of these problems like the backslashes in link, the duplicate entries in attrNames array that get added every time on patch and also the problem with the context that there isn't a way to recreate the mongo entity after initial download and that means that if orion container stops then the additional context is lost and needs to be reloaded manually, |
Ok, good, thanks for the refresh. It's actually not duplicates of one attribute. They're different attributes as the long name of the attribute (expanded from short name using the context) changes. |
I am glad that dynamic context is a first cause we plan on getting the certification powered by FIWARE soon and its good to know that nobody has done something like this before, as far you know at least. In regards to the context it remained the same while I did the above test. I noticed something very weird in mongo orionld database though. I dont have time now, but I will tell you later about it. Its extremely weird. |
So, that functional test I was going to implement about reloading the cached context, looking for a similar functest I actually found one doing exactly that. Take a look at this test: I am now inclined to think that the bug is elsewhere. Actually, I saw something really weird just now in your messages.
If we overlook the backslashes, what's in the The attrNames array is a "hack" an ex-colleague of mine from Telefonica invented (I don't like it), to find attributes quicker in a DB lookup. No need to replace those dots for rqual signs as the dots are in the RHS, so slightly quicker lookups. Now, if an attribute has the modified name "http://a=b=c/q19", in attrNames, the corresponding name must be "http://a.b.c/q19". Also, both array fields have the exact same name. What a freaking mess!!! We talk later |
If I understood correctly, you said in attrNames no values should have "." The main issues right now, as I understand them are the . in attrNames, the duplicate attrNames, and the backslashes. |
ok, now it makes more sense. Thank God !!! :)))
As an example, look at the object that is the id of an entity (old stuff coming from NGSIv1, but orion-ld is backward compatible and uses the very same DB model):
select * where _id.id == urn:ngsi-ld:test_entity_id
|
Here you can see the functest as part of the PR (that I will probably merge tomorrow - it's getting late): I believe the functest is pretty self-explanatory, but very short: What's in "--SHELL-INIT--" is startup stuff. The DB is cleaned, the broker is started and stuff like that. Then comes "--SHELL--", that's the actual commands used for the test, especially a function called orionCurl, that's just a wrapper for curl. After that comes "--REGEXPECT--". That part is compared with what came out on stdout when the SHELL part executed. Last part is called "--TEARDOWN--" and I'm not even gonna explain what that is ÷) |
context.txt |
ok, I could use that one instead in my functest, see if it changes anything. However, that's one context of yours, but then you modify it and you push it again, from what I could understand. I'll start adding traces and we'll use logging to find out more. I'll add traces tomorrow, see if we learn anything more. Pretty sure t he backslashes are in the @context, at least in the context cache of the broker. Mañana más (more tomorrow) :) |
Ok we will talk more tomorrow. One thing I need to point out, in the local test I made on a clean docker compose with no data at all I just created an entity, subscription and then added data. I never run DELETE+Reload request there, nor did I make a change in the context from what I send you in the previous message and the same problems happened again. |
What if you were to upload your context to somewhere I can see it? |
I sent you an email with the link for the context I use for orion. Now you have everything I do and you can replicate exactly what I did. |
Yeah, saw it. And I also saw the backslashes in there. I'm now preparing a very simple functest, just creating an entity using your context and then seeing the entity in mongo. |
Ok now we know the problem, I guess if I remove the backslashes from the context, the other problem with duplicate entities will be fixed. Although as I mentioned in my other comment above:
I don't think the solution with the link is the way to go for my implementation for the above reasons. Since my context can change and there is no official way to delete the downloaded context in mongo with DELETE+Reload you gave since that only affects the container, then if the container stops or is deleted all the additional context after the downloaded was saved in mongo will be lost and I will need to manually delete and reload again. |
That would be my guess as well. Try it and let me know. Now, I need to explain a little about the @context, as you are expecting some kind of "connection" between an entity and the context that was used in its creation. There is no connection whatsoever. If you then modify your context, there is no way for the broker to know that (in will stay "old" in the brokers context cache) and that's why we invented the DELETE+Reload thing. Imagine you create an entity with context A, then you update the entity 15 times with 15 different contexts. Also, remember that the longname is the real identity of an attribute. If you want this "dynamic context", I'd propose you only add items to it. Never change any items. Ah, and a bug I noticed while looking at your issue: If you feel you need any clarifications on all this, let's set up a meeting and I'll answer any questions as well as I can. |
Ah, and one more thing, important one. It's about all those fields you have in your context, e.g.
I imagine it's correct JSON-LD (haven't checked), but, Orion-LD will only be using the "@id" field out of all those fields. For various reasons I implemented my own library for handling of the context. While it would be fairly easy to add checks for "@type", I'd prefer not to, as it affects the performance of the broker. About "unit", we define a specific non-reified sub-attribute, called "unitCode" for that purpose. And, for different languages, that is taken care of by the context. You'd create a new context, with items like this;
Using a context like that, you can express your entity with greek shortnames.
Well, you'd need the prefix as well, of course (myAttributes). |
I think I may not have explained correctly what I was trying to do. Lets say the context that I host on my site looks like:
I create an entity with that context:
and at that moment since its the first time orion sees this link it downloads the context and saves it in mongo and in its cache.
The entity will be created just fine. The problem is that even though the context in the cache of the orion container will be reloaded and the new context which is:
will be added to orion container, the MongoDB context will remain:
so if for example the orion container stops or is deleted and I start it again the context that it will know is the one saved in Mongodb. So if I try to create an entity that has any of the attributes that didn't exist in the initial context that was saved in MongoDB like humidity, the entity saved in mongo wont have the correct URL for that attribute and in order to have it I will need to do DELETE+Reload first thing after I start the orion container. I don't plan on editing existing attributes in the context, I just want to be able to add attributes and for the MongoDB to also be in sync with the orion container so that if orion container stops and starts again, it will always have the MongoDB as backup to stay up to date with the latest context. |
ok, good. That's the exact bug I discovered yesterday. |
It seems I stumbled upon quite a few things that none had stumbled upon before. I think its good since now the orion ld project will be more production-ready. I learned a lot about how Orion works with these interactions. Thanks a lot. |
Yes, right back at you. |
Ok removed the backslashes from URL, tested it with Link and everything works fine now. Once you fix the mongo db bug for DELETE+Reload then it will be perfect. |
In regards to your input on context and how I use translations and units in there. My thinking about context besides the obvious use for the entity creation and subscription, is to be more like a reference page where if someone wants to find data on the attributes I use for any entity they can go there and fetch the data. I don't want to overcomplicate the structure of entities with adding unitCode and I don't want to have separate attributes that are the same as other attributes but in different language. I want a concise structure for the context page so even though it doesn't offer any benefit in regards to orion, it can help if for example some other service wants to use my entities for their benefit, to have a reference page of what the attributes I have used represent. It could also help if I want to add AI in the app later to have a concise structure with unique attributes rather than multiple attributes that represent the same thing. I don't know if my thinking is wrong. I just wanted to explain my thought process. |
ok, that's all fine. No problem whatsoever. I fixed the bug, btw. during my second meeting before lunch. |
Yes thanks to you I am aware of that, before I thought it made a difference but in the end it doesn't really matter to me if it ignores the rest of the info.
Oh that was faster than I thought. Good job! |
Boring meeting and easy fix. It's the perfect combination to get something done :))) |
OK, PR merged and everything deployed to dockerhub and quay.io. |
Tested it and it works perfectly now with link and Delete+Reload. Should I close the issue or wait for you to fix the problem I originally had when I created this issue? |
Yeah, I think it is all taken care of now :) Thank you so much for finding these issues. It's been good! |
|
ok, so, yeah, that is fixed, in this PR: #1718. |
I tested it just now locally to make sure and it still doesn't work correctly. |
Really? |
I have the above docker compose. The problem is that if orion container crashes or stops and I start it again the subscriptions made to quantumleap even though they still exist in mongo db, they don't work and when I update entity data only the orion entity data is updated and the new data doesn't get added to crate db. I have to recreate the subscriptions manually in order for them to work again. Is there any solution to this or am I doing something wrong with the setup?
The text was updated successfully, but these errors were encountered: