<commit_before>/* Copyright (c) 2009 Stanford University
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _LOG_H_
#define _LOG_H_

#include <stdint.h>
#include <shared/LogTypes.h>
#include <shared/Segment.h>
#include <shared/common.h>
#include <shared/backup_client.h>

namespace RAMCloud {

//it'd be nice if the callback could take a Log *, but the class isn't defined
//yet and we use log_eviction_cb_t in the class definition below. ugh. is there
//a solution?
typedef void (*log_eviction_cb_t)(log_entry_type_t, const void *, const uint64_t, void *);
typedef void (*log_entry_cb_t)(log_entry_type_t, const void *, const uint64_t, void *);
typedef void (*log_segment_cb_t)(Segment *, void *);

class Log {
  public:
	Log(const uint64_t, void *, const uint64_t, BackupClient *);
       ~Log();
	const void *append(log_entry_type_t, const void *, uint64_t);
	void        free(log_entry_type_t, const void *, uint64_t);
	bool        registerType(log_entry_type_t, log_eviction_cb_t, void *);
	void        printStats();
	uint64_t    getMaximumAppend();
	void init();
	uint64_t restore();
	void forEachSegment(log_segment_cb_t, uint64_t, void *);
	void forEachEntry(const Segment *, log_entry_cb_t, void *);

  private:
	void        clean(void);
	bool        newHead();
	void        checksumHead();
	void        retireHead();
	const void *appendAnyType(log_entry_type_t, const void *, uint64_t);
	log_eviction_cb_t getEvictionCallback(log_entry_type_t, void **);
	Segment    *getSegment(const void *, uint64_t);

	//XXX- fixme: should be extensible
	log_eviction_cb_t callback;
	log_entry_type_t  callback_type;
	void		 *callback_cookie;

	uint64_t max_append;		// max bytes append() can ever take
	uint64_t segment_size;		// size of each segment in bytes
	void    *base;			// base of all segments
	Segment **segments;		// array of all segments
	Segment *head;			// head of the log
	Segment *free_list;		// free (utilization == 0) segments
	uint64_t nsegments;		// total number of segments in the system
	uint64_t nfree_list;		// number of segments in free list
	uint64_t bytes_stored;		// bytes stored in the log (non-metadata only)
	bool     cleaning;		// presently cleaning the log
	BackupClient *backup;
	DISALLOW_COPY_AND_ASSIGN(Log);
};

} // namespace

#endif // !_LOG_H_
<commit_msg>Remove stupid comment.<commit_after>/* Copyright (c) 2009 Stanford University
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _LOG_H_
#define _LOG_H_

#include <stdint.h>
#include <shared/LogTypes.h>
#include <shared/Segment.h>
#include <shared/common.h>
#include <shared/backup_client.h>

namespace RAMCloud {

typedef void (*log_eviction_cb_t)(log_entry_type_t, const void *, const uint64_t, void *);
typedef void (*log_entry_cb_t)(log_entry_type_t, const void *, const uint64_t, void *);
typedef void (*log_segment_cb_t)(Segment *, void *);

class Log {
  public:
	Log(const uint64_t, void *, const uint64_t, BackupClient *);
       ~Log();
	const void *append(log_entry_type_t, const void *, uint64_t);
	void        free(log_entry_type_t, const void *, uint64_t);
	bool        registerType(log_entry_type_t, log_eviction_cb_t, void *);
	void        printStats();
	uint64_t    getMaximumAppend();
	void init();
	uint64_t restore();
	void forEachSegment(log_segment_cb_t, uint64_t, void *);
	void forEachEntry(const Segment *, log_entry_cb_t, void *);

  private:
	void        clean(void);
	bool        newHead();
	void        checksumHead();
	void        retireHead();
	const void *appendAnyType(log_entry_type_t, const void *, uint64_t);
	log_eviction_cb_t getEvictionCallback(log_entry_type_t, void **);
	Segment    *getSegment(const void *, uint64_t);

	//XXX- fixme: should be extensible
	log_eviction_cb_t callback;
	log_entry_type_t  callback_type;
	void		 *callback_cookie;

	uint64_t max_append;		// max bytes append() can ever take
	uint64_t segment_size;		// size of each segment in bytes
	void    *base;			// base of all segments
	Segment **segments;		// array of all segments
	Segment *head;			// head of the log
	Segment *free_list;		// free (utilization == 0) segments
	uint64_t nsegments;		// total number of segments in the system
	uint64_t nfree_list;		// number of segments in free list
	uint64_t bytes_stored;		// bytes stored in the log (non-metadata only)
	bool     cleaning;		// presently cleaning the log
	BackupClient *backup;
	DISALLOW_COPY_AND_ASSIGN(Log);
};

} // namespace

#endif // !_LOG_H_

{'fraction_non_alphanumeric': 0.0896551724137931, 'fraction_numerical': 0.012758620689655173, 'mean_word_length': 4.184092940125112, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5853821', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1830, 'n_words': 642}