Page MenuHomePhabricator

Creating Annotations in fast succession assigns them the same GUIDs
Closed, ResolvedPublic

Assigned To
Authored By
jungsi
Jan 25 2019, 12:04 PM
Referenced Files
F1270635: GUID2.PNG
Jan 25 2019, 12:04 PM
F1270631: GUID1.PNG
Jan 25 2019, 12:04 PM

Description

Where did I experience the bug

I created multiple Annotations in a loop.
When I tried inspecting them with the OverlayManagerPlugin it showed the properties for only the first Annotation no matter the selection.

What is the root cause of the bug

When Annotations are added to an AnnotationRenderer they are registered as a microservice and assigned a GUID in

mitk::Annotation::RegisterAsMicroservice (in Annotation.cpp starting at line 328)

The GUID is generated using a mitk::UIDGenerator("org.mitk.services.Annotation.id_", 16)
As this function is called in fast succession (in the same second) the time portion for the GUID is the same.
The issue is that the following random part of the GUID also happens to be the same.

When I add annotations in a loop and log the generated GUIDs I get

GUID1.PNG (183×1 px, 30 KB)

When I sleep for two seconds inbetween each annotation this is the resulting log output

GUID2.PNG (189×1 px, 31 KB)

Event Timeline

jungsi created this task.

One question: Did I understood it correctly, each annotation is added as a microservice? So when I add two Label annotations, I will have to additional microservice instances registered?

Yes, that is correct

void mitk::Annotation::RegisterAsMicroservice(us::ServiceProperties props)
{
  if (m_ServiceRegistration != nullptr)
    m_ServiceRegistration.Unregister();
  us::ModuleContext *context = us::GetModuleContext();
  // Define ServiceProps
  mitk::UIDGenerator uidGen = mitk::UIDGenerator("org.mitk.services.Annotation.id_", 16);
  props[US_PROPKEY_ID] = uidGen.GetUID();
  m_ServiceRegistration =
    context->RegisterService(this, props);
}

When I query the service registry I receive multiple service references.

Oh, uh. One can do it that way, but I am not sure if I would realy like to have each instance of an annotation as an on service in the registry. In other cases (like property aliasis or descriptions) we have one service and you register the specific instances there. But I will open up another tasks for this discussion.

steint claimed this task.

Deleted branch T25927-fix-uid-generation.