apache / apache/bookkeeper

Question regarding refcount of ByteBuf in our client API

Offen
#1,237 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
triage/week-33
Vorherrschende Sprache
Java
Sterne
2k
Forks
975
Ø Merge
6 T. 15 Std.
Gemergte PRs (30 T.)
7

Beschreibung

**QUESTION**

Regarding the refcount of ByteBuf, from what I understand the API method which takes ByteBuf as argument shouldn't increase or decrease the refcount of 'ReferenceCounted' object.

I mean
```
myApplicationMethod() {

ByteBuf byteBuf = createNewInstanceOfByteBuf();
...
APIClass.APIMethod(bytebuf);
...
byteBuf.release();
}
```
here when I create byteBuf the refCount would typically be 1. Now by passing this refcounted object to the standard API method, I don’t expect the APIMethod to decrease the refCount (modify refCount) and finally it is the responsibility of the caller (application) method to release it by calling release method explicitly when they are done with the byteBuf.

But in our case WriteAdvHandle.write(long entryId, ByteBuf data) is decreasing the refcount, this is because of https://github.com/apache/bookkeeper/blob/master/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java#L422 .

**Que:** Why are we doing this? What is the general practice with regards to usage of refcounted objects in API methods? Have we mentioned the expected behavior in detail in our API docs?

Are we doing corresponding release calls in all the places where ByteBuff is created. https://netty.io/4.0/api/io/netty/util/ReferenceCounted.html says that initial count would be 1 when an ReferenceCounted object is created.

Are there enough documentation/comments in code/invariant checks/testcases at each layer for ByteBuf usage in our Client and Server code?

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start with bookkeeper-server/src/main/java/org/apache/bookkeeper/client/PendingAddOp.java around the referenced release call, then compare the Client and Server ByteBuf creation and release paths with Netty's ReferenceCounted documentation. Determine the ownership contract for WriteAdvHandle.write(long entryId, ByteBuf data) and identify the relevant documentation, comments, invariant checks, or tests needed to make that contract explicit.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
api, backend, distributed-systems
Issue-Typ
Dokumentation
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
30/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.