Blame source/vdo/base/hashZone.h

Packit Service 310c69
/*
Packit Service 310c69
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service 310c69
 *
Packit Service 310c69
 * This program is free software; you can redistribute it and/or
Packit Service 310c69
 * modify it under the terms of the GNU General Public License
Packit Service 310c69
 * as published by the Free Software Foundation; either version 2
Packit Service 310c69
 * of the License, or (at your option) any later version.
Packit Service 310c69
 * 
Packit Service 310c69
 * This program is distributed in the hope that it will be useful,
Packit Service 310c69
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 310c69
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 310c69
 * GNU General Public License for more details.
Packit Service 310c69
 * 
Packit Service 310c69
 * You should have received a copy of the GNU General Public License
Packit Service 310c69
 * along with this program; if not, write to the Free Software
Packit Service 310c69
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 310c69
 * 02110-1301, USA. 
Packit Service 310c69
 *
Packit Service 310c69
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/hashZone.h#1 $
Packit Service 310c69
 */
Packit Service 310c69
Packit Service 310c69
#ifndef HASH_ZONE_H
Packit Service 310c69
#define HASH_ZONE_H
Packit Service 310c69
Packit Service 310c69
#include "uds.h"
Packit Service 310c69
Packit Service 310c69
#include "statistics.h"
Packit Service 310c69
#include "types.h"
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Create a hash zone.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  vdo         The VDO to which the zone will belong
Packit Service 310c69
 * @param [in]  zoneNumber  The number of the zone to create
Packit Service 310c69
 * @param [out] zonePtr     A pointer to hold the new HashZone
Packit Service 310c69
 *
Packit Service 310c69
 * @return VDO_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int makeHashZone(VDO *vdo, ZoneCount zoneNumber, HashZone **zonePtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Free a hash zone and null out the reference to it.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zonePtr  A pointer to the zone to free
Packit Service 310c69
 **/
Packit Service 310c69
void freeHashZone(HashZone **zonePtr);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the zone number of a hash zone.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zone  The zone
Packit Service 310c69
 *
Packit Service 310c69
 * @return The number of the zone
Packit Service 310c69
 **/
Packit Service 310c69
ZoneCount getHashZoneNumber(const HashZone *zone)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the ID of a hash zone's thread.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zone  The zone
Packit Service 310c69
 *
Packit Service 310c69
 * @return The zone's thread ID
Packit Service 310c69
 **/
Packit Service 310c69
ThreadID getHashZoneThreadID(const HashZone *zone)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the statistics for this hash zone.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zone  The hash zone to query
Packit Service 310c69
 *
Packit Service 310c69
 * @return A copy of the current statistics for the hash zone
Packit Service 310c69
 **/
Packit Service 310c69
HashLockStatistics getHashZoneStatistics(const HashZone *zone)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Get the lock for the hash (chunk name) of the data in a DataVIO, or if one
Packit Service 310c69
 * does not exist (or if we are explicitly rolling over), initialize a new
Packit Service 310c69
 * lock for the hash and register it in the zone. This must only be called in
Packit Service 310c69
 * the correct thread for the zone.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]  zone         The zone responsible for the hash
Packit Service 310c69
 * @param [in]  hash         The hash to lock
Packit Service 310c69
 * @param [in]  replaceLock  If non-NULL, the lock already registered for the
Packit Service 310c69
 *                           hash which should be replaced by the new lock
Packit Service 310c69
 * @param [out] lockPtr      A pointer to receive the hash lock
Packit Service 310c69
 *
Packit Service 310c69
 * @return VDO_SUCCESS or an error code
Packit Service 310c69
 **/
Packit Service 310c69
int acquireHashLockFromZone(HashZone            *zone,
Packit Service 310c69
                            const UdsChunkName  *hash,
Packit Service 310c69
                            HashLock            *replaceLock,
Packit Service 310c69
                            HashLock           **lockPtr)
Packit Service 310c69
  __attribute__((warn_unused_result));
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Return a hash lock to the zone it was borrowed from, remove it from the
Packit Service 310c69
 * zone's lock map, returning it to the pool, and nulling out the reference to
Packit Service 310c69
 * it. This must only be called when the lock has been completely released,
Packit Service 310c69
 * and only in the correct thread for the zone.
Packit Service 310c69
 *
Packit Service 310c69
 * @param [in]     zone     The zone from which the lock was borrowed
Packit Service 310c69
 * @param [in,out] lockPtr  The lock that is no longer in use
Packit Service 310c69
 **/
Packit Service 310c69
void returnHashLockToZone(HashZone *zone, HashLock **lockPtr);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Increment the valid advice count in the hash zone statistics.
Packit Service 310c69
 * Must only be called from the hash zone thread.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zone  The hash zone of the lock that received valid advice
Packit Service 310c69
 **/
Packit Service 310c69
void bumpHashZoneValidAdviceCount(HashZone *zone);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Increment the stale advice count in the hash zone statistics.
Packit Service 310c69
 * Must only be called from the hash zone thread.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zone  The hash zone of the lock that received stale advice
Packit Service 310c69
 **/
Packit Service 310c69
void bumpHashZoneStaleAdviceCount(HashZone *zone);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Increment the concurrent dedupe count in the hash zone statistics.
Packit Service 310c69
 * Must only be called from the hash zone thread.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zone  The hash zone of the lock that matched a new DataVIO
Packit Service 310c69
 **/
Packit Service 310c69
void bumpHashZoneDataMatchCount(HashZone *zone);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Increment the concurrent hash collision count in the hash zone statistics.
Packit Service 310c69
 * Must only be called from the hash zone thread.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zone  The hash zone of the lock that rejected a colliding DataVIO
Packit Service 310c69
 **/
Packit Service 310c69
void bumpHashZoneCollisionCount(HashZone *zone);
Packit Service 310c69
Packit Service 310c69
/**
Packit Service 310c69
 * Dump information about a hash zone to the log for debugging.
Packit Service 310c69
 *
Packit Service 310c69
 * @param zone   The zone to dump
Packit Service 310c69
 **/
Packit Service 310c69
void dumpHashZone(const HashZone *zone);
Packit Service 310c69
Packit Service 310c69
#endif // HASH_ZONE_H