Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the function of ReferenceCountedACLCache in zk

Shulou Source: shulou.com Published: 2022-06-02 10:32:14 09月30日 Update

This article introduces what is the role of ReferenceCountedACLCache in zk, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Function: complete the conversion between LIst and Long. Acl in DataNode is a long value, not an ACL list.

Spatial complexity: inner class AtomicLongWithEquals

Attributes:

/ / log information private static final Logger LOG = LoggerFactory.getLogger (ReferenceCountedACLCache.class); / / long ACL list correspondence final Map longKeyMap = new HashMap (); / / ACL list long correspondence final Map aclKeyMap = new HashMap (); final Map referenceCounter = new HashMap (); private static final long OPEN_UNSAFE_ACL_ID =-1L * * these are the number of acls that we have in the datatree * / long aclIndex = 0

Methods:

Record the number of references

Private static class AtomicLongWithEquals extends AtomicLong {private static final long serialVersionUID = 3355155896813725462L; public AtomicLongWithEquals (long I) {super (I);} @ Override public boolean equals (Object o) {if (this = = o) {return true;} if (o = = null | | getClass ()! = o.getClass ()) {return false;} return equals ((AtomicLongWithEquals) o) } public boolean equals (AtomicLongWithEquals that) {return get () = = that.get ();} @ Override public int hashCode () {return 31 * Long.valueOf (get ()). HashCode ();}} add use public synchronized void addUsage (Long acl) {if (acl = = OPEN_UNSAFE_ACL_ID) {return } if (! longKeyMap.containsKey (acl)) {LOG.info ("Ignoring acl" + acl + "as it does not exist in the cache"); return;} AtomicLong count = referenceCounter.get (acl); if (count = = null) {referenceCounter.put (acl, new AtomicLongWithEquals (1));} else {count.incrementAndGet () }} / / remove reference public synchronized void removeUsage (Long acl) {if (acl = = OPEN_UNSAFE_ACL_ID) {return;} if (! longKeyMap.containsKey (acl)) {LOG.info ("Ignoring acl" + acl + "as it does not exist in the cache"); return;} long newCount = referenceCounter.get (acl). DecrementAndGet (); if (newCount)

Tags: Role information content more help good complex interest guys buddies attributes articles methods logs times knowledge space articles references Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information vpn MySQL Apple