From c367e50f16831539d6729d2d50e560d6c2f194a4 Mon Sep 17 00:00:00 2001 From: jiangbuyun Date: Fri, 17 Jun 2022 09:14:33 +0800 Subject: [PATCH] =?UTF-8?q?repchain2.0-update70:=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E5=92=8C=E6=93=8D=E4=BD=9C=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E9=9C=80=E8=A6=81=E8=AF=BB=E5=8F=96=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E9=93=BE=E5=92=8C=E5=9F=BA=E7=A1=80=E9=93=BE=E7=9A=84?= =?UTF-8?q?=E5=B9=B6=E9=9B=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cache/AuthenticateIndexCache.scala | 32 +++++++++++++++++-- .../scala/rep/authority/cache/ICache.scala | 4 +-- .../authority/cache/OperateIndexCache.scala | 30 +++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/src/main/scala/rep/authority/cache/AuthenticateIndexCache.scala b/src/main/scala/rep/authority/cache/AuthenticateIndexCache.scala index 40d964c7..8af3a264 100644 --- a/src/main/scala/rep/authority/cache/AuthenticateIndexCache.scala +++ b/src/main/scala/rep/authority/cache/AuthenticateIndexCache.scala @@ -1,8 +1,7 @@ package rep.authority.cache import rep.app.system.RepChainSystemContext -import rep.authority.cache.AuthenticateCache.authData -import rep.proto.rc2.Authorize +import rep.log.RepLogger import rep.sc.tpl.did.DidTplPrefix import rep.storage.chain.preload.BlockPreload import rep.utils.IdTool @@ -38,6 +37,35 @@ class AuthenticateIndexCache(ctx : RepChainSystemContext) extends ICache(ctx) { IdTool.WorldStateKeySeparator + DidTplPrefix.authIdxPrefix } + override protected def readData(key: String, blockPreload: BlockPreload): Option[Any] = { + var r = this.cache.getOrDefault(key, None) + if (r == None) { + RepLogger.Permission_Logger.trace(s"AuthenticateIndexCache.readData asynchronous read,from IdentityNet,key=${key}") + //获取数据方式,0:从基础链获取;1:从业务链获取; + val base = this.dataTypeConvert(this.db.getObject(this.getBaseNetworkPrefix + key), blockPreload) + val business = this.dataTypeConvert(this.db.getObject(this.getBaseNetworkPrefix + key), blockPreload) + if (base != None) { + if (business != None) { + val base1 = base.get.asInstanceOf[Array[String]] + val business1 = business.get.asInstanceOf[Array[String]] + r = Some(Array.concat(base1, business1)) + } else { + r = base + } + } else { + if (business != None) { + r = business + } else { + r = None + } + } + if (r != None) { + this.cache.put(key, r) + } + } + r + } + def get(key:String,blockPreload: BlockPreload):Option[Array[String]]={ val d = this.getData(key,blockPreload) if(d == None) diff --git a/src/main/scala/rep/authority/cache/ICache.scala b/src/main/scala/rep/authority/cache/ICache.scala index 4918eac4..00d56800 100644 --- a/src/main/scala/rep/authority/cache/ICache.scala +++ b/src/main/scala/rep/authority/cache/ICache.scala @@ -21,7 +21,7 @@ abstract class ICache(ctx: RepChainSystemContext) { config, cid.chaincodeName) final val business_prefix : String = KeyPrefixManager.getCustomNetKeyPrefix( ctx.getConfig.getChainNetworkId,cid.chaincodeName) - final private val db = DBFactory.getDBAccess(config) + final protected val db = DBFactory.getDBAccess(config) final protected val cacheMaxSize = config.getAccountCacheSize final protected implicit val cache = new ConcurrentLinkedHashMap.Builder[String, Option[Any]]() .maximumWeightedCapacity(cacheMaxSize) @@ -39,7 +39,7 @@ abstract class ICache(ctx: RepChainSystemContext) { protected def getCacheType: String - private def readData(key: String, blockPreload: BlockPreload): Option[Any] = { + protected def readData(key: String, blockPreload: BlockPreload): Option[Any] = { val r = this.cache.getOrDefault(key, None) if (r == None) { RepLogger.Permission_Logger.trace(s"ICache.readData asynchronous read,from IdentityNet,key=${key}") diff --git a/src/main/scala/rep/authority/cache/OperateIndexCache.scala b/src/main/scala/rep/authority/cache/OperateIndexCache.scala index 0f49fcf1..6c54c569 100644 --- a/src/main/scala/rep/authority/cache/OperateIndexCache.scala +++ b/src/main/scala/rep/authority/cache/OperateIndexCache.scala @@ -1,6 +1,7 @@ package rep.authority.cache import rep.app.system.RepChainSystemContext +import rep.log.RepLogger import rep.sc.tpl.did.DidTplPrefix import rep.storage.chain.preload.BlockPreload import rep.utils.IdTool @@ -36,6 +37,35 @@ class OperateIndexCache(ctx : RepChainSystemContext) extends ICache(ctx){ IdTool.WorldStateKeySeparator + DidTplPrefix.operIdxPrefix } + override protected def readData(key: String, blockPreload: BlockPreload): Option[Any] = { + var r = this.cache.getOrDefault(key, None) + if (r == None) { + RepLogger.Permission_Logger.trace(s"AuthenticateIndexCache.readData asynchronous read,from IdentityNet,key=${key}") + //获取数据方式,0:从基础链获取;1:从业务链获取; + val base = this.dataTypeConvert(this.db.getObject(this.getBaseNetworkPrefix + key), blockPreload) + val business = this.dataTypeConvert(this.db.getObject(this.getBaseNetworkPrefix + key), blockPreload) + if (base != None) { + if (business != None) { + val base1 = base.get.asInstanceOf[Array[String]] + val business1 = business.get.asInstanceOf[Array[String]] + r = Some(Array.concat(base1, business1)) + } else { + r = base + } + } else { + if (business != None) { + r = business + } else { + r = None + } + } + if (r != None) { + this.cache.put(key, r) + } + } + r + } + def get(key:String,blockPreload: BlockPreload):Option[Array[String]]={ val d = this.getData(key,blockPreload) if(d == None)