hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bing Li <lbl...@gmail.com>
Subject Is "synchronized" required?
Date Mon, 04 Feb 2013 20:20:07 GMT
Dear all,

When writing data into HBase, sometimes I got exceptions. I guess they
might be caused by concurrent writings. But I am not sure.

My question is whether it is necessary to put "synchronized" before
the writing methods? The following lines are the sample code.

I think the directive, synchronized, must lower the performance of
writing. Sometimes concurrent writing is needed in my system.

Thanks so much!

Best wishes,
Bing

public synchronized void AddDomainNodeRanks(String domainKey, int
timingScale, Map<String, Double> nodeRankMap)
{
      List<Put> puts = new ArrayList<Put>();
      Put domainKeyPut;
      Put timingScalePut;
      Put nodeKeyPut;
      Put rankPut;

      byte[] domainNodeRankRowKey;

      for (Map.Entry<String, Double> nodeRankEntry : nodeRankMap.entrySet())
      {
          domainNodeRankRowKey =
Bytes.toBytes(RankStructure.DOMAIN_NODE_RANK_ROW +
Tools.GetAHash(domainKey + timingScale + nodeRankEntry.getKey()));

         domainKeyPut = new Put(domainNodeRankRowKey);
         domainKeyPut.add(RankStructure.DOMAIN_NODE_RANK_FAMILY,
RankStructure.DOMAIN_NODE_RANK_DOMAIN_KEY_COLUMN,
Bytes.toBytes(domainKey));
         puts.add(domainKeyPut);

         timingScalePut = new Put(domainNodeRankRowKey);
         timingScalePut.add(RankStructure.DOMAIN_NODE_RANK_FAMILY,
RankStructure.DOMAIN_NODE_RANK_TIMING_SCALE_COLUMN,
Bytes.toBytes(timingScale));
        puts.add(timingScalePut);

        nodeKeyPut = new Put(domainNodeRankRowKey);
        nodeKeyPut.add(RankStructure.DOMAIN_NODE_RANK_FAMILY,
RankStructure.DOMAIN_NODE_RANK_NODE_KEY_COLUMN,
Bytes.toBytes(nodeRankEntry.getKey()));
        puts.add(nodeKeyPut);

        rankPut = new Put(domainNodeRankRowKey);
        rankPut.add(RankStructure.DOMAIN_NODE_RANK_FAMILY,
RankStructure.DOMAIN_NODE_RANK_RANKS_COLUMN,
Bytes.toBytes(nodeRankEntry.getValue()));
        puts.add(rankPut);
     }

     try
     {
         this.rankTable.put(puts);
     }
     catch (IOException e)
     {
         e.printStackTrace();
     }
}

Mime
View raw message